Class hierarchies should be deep and narrow

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: A good class hierarchy design should be several layers deep. In a good design, a base class should not have large number of direct children classes (i.e. a superclass has 28 subclasses). I...)
 
Line 2: Line 2:
  
 
Solution for solving this problem is to find some common behaviors from the children sibling classes, and then extract these common behaviors into a parent class under the original base parent class.
 
Solution for solving this problem is to find some common behaviors from the children sibling classes, and then extract these common behaviors into a parent class under the original base parent class.
 +
 +
[[Riel's heuristics|Riel's heuristic]] [[Favour deep hierarchies]] is derived from this idea.
 +
 +
== See also ==
 +
* [[Favour deep heirarchies]]

Revision as of 03:43, 6 October 2008

A good class hierarchy design should be several layers deep. In a good design, a base class should not have large number of direct children classes (i.e. a superclass has 28 subclasses). If a class hierarchy is not deep but very wide, it is a sign that a change is needed.

Solution for solving this problem is to find some common behaviors from the children sibling classes, and then extract these common behaviors into a parent class under the original base parent class.

Riel's heuristic Favour deep hierarchies is derived from this idea.

See also

Personal tools