Designing for subclassing
To create an extendable class:
- all constructors, readObject, and clone must not invoke an overridable method (one that is not static, private, or final)
- if a method depends on an implementation of a overridable method, this dependence must be explicitly stated in its javadoc
- don't implement Serializable unless you absolutely need to
- don't implement Cloneable unless you absolutely need to
- subclass the default implementation directly
- use the default implementation as a field, and forward calls to it
- ignore the default implementation, and implement the interface entirely from scratch
See Also :
Use final liberally
Serialization and subclassing
Avoid clone
Overridable methods need special care
Remember styles of inheritance
Constructors shouldn't call overridables
Serialization and subclassing
Avoid clone
Overridable methods need special care
Remember styles of inheritance
Constructors shouldn't call overridables
Would you use this technique?