Avoid concrete base classes

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
Line 4: Line 4:
  
 
Riel states that all base classes of an inheritance hierarchy should be abstract. Note that this does not mean that single classes with no inheritance hierarchy should be made abstract, as this would mean a concrete subclass would have to be created that adds no meaningful functionality - this violates Heuristic 3.7; [[Eliminate irrelevant classes]].
 
Riel states that all base classes of an inheritance hierarchy should be abstract. Note that this does not mean that single classes with no inheritance hierarchy should be made abstract, as this would mean a concrete subclass would have to be created that adds no meaningful functionality - this violates Heuristic 3.7; [[Eliminate irrelevant classes]].
 +
 +
This heuristic is a trade off between design complexity and flexibility. The example Riel gives (taken from the Object Oriented Design Heuristics book) is a FullEmployee class that inherits from a NewEmployee class. It seems to tie in with [[Avoid inheritance for implementation]]. In this case we cannot add something to the NewEmployee class without it also being added (via inheritance) to the FullEmployee class.
 +
 +
[[Image:5.7 example1.png]]
  
 
More to come...
 
More to come...
Line 10: Line 14:
 
* [[Riel's heuristics]]
 
* [[Riel's heuristics]]
 
* [[Eliminate irrelevant classes]]
 
* [[Eliminate irrelevant classes]]
 +
* [[Avoid inheritance for implementation]]

Revision as of 00:30, 3 September 2008

Riel's heuristic #5.7: All base classes should be abstract classes.

What does Riel mean? Does he give an example? Have we got any examples of our own? Do we believe Riel?

Riel states that all base classes of an inheritance hierarchy should be abstract. Note that this does not mean that single classes with no inheritance hierarchy should be made abstract, as this would mean a concrete subclass would have to be created that adds no meaningful functionality - this violates Heuristic 3.7; Eliminate irrelevant classes.

This heuristic is a trade off between design complexity and flexibility. The example Riel gives (taken from the Object Oriented Design Heuristics book) is a FullEmployee class that inherits from a NewEmployee class. It seems to tie in with Avoid inheritance for implementation. In this case we cannot add something to the NewEmployee class without it also being added (via inheritance) to the FullEmployee class.

5.7 example1.png

More to come...

See also

Personal tools