Introduce common base class
From CSSEMediaWiki
(Difference between revisions)
BenMcDonald (Talk | contribs) |
m (Reverted edits by Ebybymic (Talk); changed back to last version by BenMcDonald) |
(One intermediate revision by one user not shown) |
Latest revision as of 03:21, 25 November 2010
- If two or more classes have common data and behavior (i.e. methods) then those classes should each inherit from a common base class which captures those data and methods. --Riel's Heuristic 5.10, Arthur Riel 1996
Example
The two classes Dog and Bird have common data (weight) and behaviour (eat() and sleep()).
A new class called Animal is created that both Dog and Bird inherit.