Subclasses should be specializations

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: 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 s...)
 
Line 1: Line 1:
 
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.
 
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. They uses subclass 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.
+
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.

Revision as of 02:35, 5 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.

Personal tools