摘要:
Inheritance disadvantage
Unlike method invocation, inheritance violates encapsulation. Since you don't know the super class implementation which may involve some unpredictable calling between different methods of super class. And it is difficult to maintain the subclass when there is a change of the super class. 阅读全文
阅读排行榜
Effective Java 08 Obey the general contract when overriding equals
2014-03-02 12:34 by 小郝(Kaibo Hao), 535 阅读, 收藏,
摘要:
When it's the case that each instance of the class is equal to only itself.
1. Each instance of the class is inherently unique.
2. You don't care whether the class provides a "logical equality" test.
3. If a superclass has already overridden equals, and the superclass behavior is appropriate for this class.
4. The class is private or package-private, and you are certain that its equals method will never be invoked. 阅读全文
Effective Java 34 Emulate extensible enums with interfaces
2014-03-28 16:54 by 小郝(Kaibo Hao), 534 阅读, 收藏,
摘要:
While you cannot write an extensible enum type, you can emulate it by writing an interface to go with a basic enum type that implements the interface. 阅读全文
Effective Java 70 Document thread safety
2014-05-04 08:54 by 小郝(Kaibo Hao), 526 阅读, 收藏,
摘要:
Every class should clearly document its thread safety properties with a carefully worded prose description or a thread safety annotation. The synchronized modifier plays no part in this documentation. Conditionally thread-safe classes must document which method invocation sequences require external synchronization, and which lock to acquire when executing these sequences. If you write an unconditionally thread-safe class, consider using a private lock object in place of synchronized methods. Thi 阅读全文
Effective Java 11 Override clone judiciously
2014-03-06 22:17 by 小郝(Kaibo Hao), 524 阅读, 收藏,
摘要:
Principles
If you override the clone method in a nonfinal class, you should return an object obtained by invoking super.clone
In practice, a class that implements Cloneable is expected to provide a properly functioning public clone method.
Never make the client do anything the library can do for the client.
The clone architecture is incompatible with normal use of final fields referring to mutable objects 阅读全文
Effective C# 学习笔记(三)在类型转换上多使用 as 和 is
2011-07-02 23:12 by 小郝(Kaibo Hao), 521 阅读, 收藏,
摘要:
cast/as/is你能分清他们的用法么?在什么情况下有限制?何种场景下用? 阅读全文
Effective C# 学习笔记(二十)不可变的原子值类型的好处
2011-07-13 16:03 by 小郝(Kaibo Hao), 520 阅读, 收藏,
摘要:
不变的原子值类型指的是那些其每一个属性可能因任何一个属性的改变而需改变,每个属性都不能独立更新的类型。这种类型的实现方式有许多要注意的地方,主要目的是防止在赋值时出现非法临时状态,可以使用构造函数赋值和Copy创建可变类型属性的方法来保证其数据的合法性。 阅读全文
Effective C# 学习笔记(十二) 多用成员变量初始化,少用指定赋值
2011-07-05 22:49 by 小郝(Kaibo Hao), 518 阅读, 收藏,
摘要:
由于构造函数可以重载,对于成员变量的初始化最好还是在声明时赋值,以免重载后忘记赋值,而成员变量的赋值会在构造函数执行前执行 阅读全文
NHibernate学习笔记(5)—正向与反向生成
2009-10-07 20:06 by 小郝(Kaibo Hao), 516 阅读, 收藏,
摘要:
继续,看了NHibernate之旅(18):初探代码生成工具使用(new!)、NHibernate之旅(19):初探SchemaExport工具使用(new!)、NHibernate之旅(20):再探SchemaExport工具使用(new!)这三篇文章后。自己也试了试。发现代码生成没有什么变化... 阅读全文
Effective Java 72 Don't depend on the thread scheduler
2014-05-06 08:52 by 小郝(Kaibo Hao), 515 阅读, 收藏,
摘要:
Do not depend on the thread scheduler for the correctness of your program. The resulting program will be neither robust nor portable. As a corollary, do not rely on Thread.yield or thread priorities. These facilities are merely hints to the scheduler. Thread priorities may be used sparingly to improve the quality of service of an already working program, but they should never be used to "fix" a program that barely works. 阅读全文
浙公网安备 33010602011771号