Beware inheritance over composition

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: ''If you have an example of multiple inheritance in your design, assume you have made a mistake and prove otherwise.'' -- Riel's Heuristic 6.2, Arthur Riel 1996 == Explanation == == ...)
 
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
''If you have an example of multiple inheritance in your design, assume you have made a mistake and prove otherwise.'' -- Riel's Heuristic 6.2, [[Arthur Riel 1996]]
+
''Whenever there is inheritance in an object-oriented design ask yourself two questions: 1) Am I a special type of the thing I'm inheriting from? and 2) Is the thing I'm inheriting from part of me?'' -- Riel's Heuristic 6.2, [[Arthur Riel 1996]]
 +
 
 
== Explanation ==
 
== Explanation ==
 
+
Riel believes that inheritance should be treated with care. Before using it, the design decision should be questioned. Does it make sense for this class to be a subclass of another, is the class actually a generalised type of me?
  
 
== See also ==
 
== See also ==
 
* [[Riel's heuristics]]
 
* [[Riel's heuristics]]
 +
* [[Favor composition over inheritance]]
 
* [[Multiple Inheritance]]
 
* [[Multiple Inheritance]]
 
+
* [[Avoid multiple inheritance]]
  
 
[[Category:Riel's heuristics]]
 
[[Category:Riel's heuristics]]

Latest revision as of 22:18, 28 July 2009

Whenever there is inheritance in an object-oriented design ask yourself two questions: 1) Am I a special type of the thing I'm inheriting from? and 2) Is the thing I'm inheriting from part of me? -- Riel's Heuristic 6.2, Arthur Riel 1996

Explanation

Riel believes that inheritance should be treated with care. Before using it, the design decision should be questioned. Does it make sense for this class to be a subclass of another, is the class actually a generalised type of me?

See also

Personal tools