Singelton - use a public static final varible and a private constructor, to guarantee single instance. If serializable, provide readResolve() to return this instance.
Magic GC - whenever a class (Stack) manages its own memory, be careful of memory leak. Another common source of leak is cache. LinkedHashMap.removeEldestEntry.
Equals and Comparable - Override hashCode whenever override equals.
Cloneable - all classes implement Cloneable should override clone with a public method. The method sould call super.clone first, and copy mutable fields. Better to use copy constructor.
Proteced - private, package private(default), protected and public. Subclass method override superclass method can not have lower access level.
Decorator - composition and forwarding
Magic GC - whenever a class (Stack) manages its own memory, be careful of memory leak. Another common source of leak is cache. LinkedHashMap.removeEldestEntry.
Equals and Comparable - Override hashCode whenever override equals.
Cloneable - all classes implement Cloneable should override clone with a public method. The method sould call super.clone first, and copy mutable fields. Better to use copy constructor.
Proteced - private, package private(default), protected and public. Subclass method override superclass method can not have lower access level.
Decorator - composition and forwarding
Comments
Post a Comment