The top of the class hierarchy should be abstract

From CSSEMediaWiki
Jump to: navigation, search

This idea is very tightly related to Riel's heuristic Avoid concrete base classes. It states that the class at the top of a class hierarchy should be abstract, and if it is not then there may be a design problem. If a subclass B overrides methods in its concrete superclass A, it may indicate that there should be a common abstract superclass to A and B which defines common behaviour; then neither A or B need to redefine any methods. An example of this is given in Avoid concrete base classes.

There are some instances where this heuristic conflicts with the Lazy class smell. We found this in the Parse tree design where we were trying to model two different kinds of tokens: standard tokens and value tokens which added extra functionality to the Token class. In this case, we made ValueToken a subclass of the Token class and made the Token class concrete, thus violating this heuristic. The alternative would have been to make the Token class abstract and add a concrete subclass with no additional functionality. This would have been a lazy class.

See Also

Personal tools