看smack的时候,发现作者提出了几个开发的实践(http://community.igniterealtime.org/docs/DOC-1984),转载过来,并初步翻译了一下[抱歉,翻译的有点烂],虽然很容易理解,但很有意思,对我们的编程有借鉴意义。
- To convert a primitive to a String use String.valueOf(...). Don't use "" + i.
- To convert from a primitive use Integer.parseInt(...) and similar.
- Don't use StringBuffer unless you need threadsafety, use StringBuilder instead.
- Similarly don't use Vector, use ArrayList.
- Code to interfaces instead of specific implementations (Collection or List instead of ArrayList).
- Never subclass Thread, always pass a Runnable into the constructor instead.
- If equals is implemented in a class it is MANDATORY to implement hashCode as well, otherwise HashSets and other classes which rely on the contract of hashCode will not work. IDEs like Eclipse provide generators to implement equals and hashCode.
- Use enum instead of a bunch of static final int fields. Then you have type safety for related constants and more readable debugging output is possible because you get meaningful names instead of "magic" numbers.
- Avoid the use of static methods and attributes if possible. This is not good object oriented programming style and it also makes testing your code more difficult.
3万+



被折叠的 条评论
为什么被折叠?



