Subclasses should be specializations
Line 2: | Line 2: | ||
However, the author also noticed there are some cases which might be good to be an exception from the rule defined above. One example is the case of an abstract superclass. In such a case, subclass have also to fill in the method which required by the superclass. Secondly, they suggests some times subclass doesn’t need to be a specialization of the superclass. Subclass can be used as a way for fixing improper design in legacy code by adding subclass to the base class. As a reault, subclass could be more general than its superclass, or may not have much relationship to the super class but just for the purpose of code reuse. A further reorganization of the class hierarchy is necessary if we fall into this kind of situation. | However, the author also noticed there are some cases which might be good to be an exception from the rule defined above. One example is the case of an abstract superclass. In such a case, subclass have also to fill in the method which required by the superclass. Secondly, they suggests some times subclass doesn’t need to be a specialization of the superclass. Subclass can be used as a way for fixing improper design in legacy code by adding subclass to the base class. As a reault, subclass could be more general than its superclass, or may not have much relationship to the super class but just for the purpose of code reuse. A further reorganization of the class hierarchy is necessary if we fall into this kind of situation. | ||
+ | |||
+ | Riel's heuristic [[Inheritance for specialization]] is derived from this idea. | ||
+ | |||
+ | == See also == | ||
+ | * [[Inheritance for specialization]] | ||
+ | * [[Design maxims]] |
Revision as of 03:44, 6 October 2008
Johnson and Foote defined that subclass should be considered as a specialized entity of the superclass. Hence subclass does not redefine any of the method which is already defined in the superclass but only adding new methods.
However, the author also noticed there are some cases which might be good to be an exception from the rule defined above. One example is the case of an abstract superclass. In such a case, subclass have also to fill in the method which required by the superclass. Secondly, they suggests some times subclass doesn’t need to be a specialization of the superclass. Subclass can be used as a way for fixing improper design in legacy code by adding subclass to the base class. As a reault, subclass could be more general than its superclass, or may not have much relationship to the super class but just for the purpose of code reuse. A further reorganization of the class hierarchy is necessary if we fall into this kind of situation.
Riel's heuristic Inheritance for specialization is derived from this idea.