Contain contents not parents

From CSSEMediaWiki
Revision as of 02:49, 23 July 2009 by AlexGee (Talk | contribs)
Jump to: navigation, search
A class must know what it contains, but it should never know who contains it. --Riel's Heuristic 4.13, Arthur Riel 1996

This heuristic refers to the idea that classes should not know what objects contain them as this makes them far less reusable (). If a class is designed for a specific use and is dependent on a parent object, it can't then be used inside a different type of parent object. For example, Riel uses the example of a BedRoom containing a Clock. The BedRoom object must know about the Clock object inside it. However if Clock knows about and depends on BedRoom then it can not then be reused inside another object for example a TimeLockSafe object.

The Chain of Responsibility design pattern violates this heuristic.

Personal tools