272: Highlights
- Class hierarchies reflect subclasssuperclass relations among classes.
- You have several reasons to arrange classes in hierarchies:
- To parallel natural categories
- To prevent avoidable duplication and to simplify maintenance
- To avoid introducing bugs into previously debugged code
- To use purchased code
When a subclasssuperclass relation is direct, with no intervening
classes, the subclass is called the direct subclass, and the superclass
is called the direct superclass.
A class inherits public instance variables and public instance methods from all
its superclasses.
When a subclasssuperclass chain contains multiple instance methods
with the same name, argument number, and argument types, the one closest
to the class of the target instance in the subclasssuperclass chain is
the one executed. All others are shadowed.
If you want to create a class hierarchy, then draw a diagram that
reflects natural categories. Populate the classes in that class
hierarchy with public instance variables and public instance methods
such that there is no needless duplication of an instance variable or
instance method, and such that each public instance variable and public
instance method is useful to instances of every subclass.
If you want to create a direct-subclassdirect-superclass relation,
then instantiate the following pattern:
public class subclass name extends superclass name {
...
}