Introduce common base class
From CSSEMediaWiki
(Difference between revisions)
BenMcDonald (Talk | contribs) (New page: If two or more classes have common data and behaviour then those classes should each inherit from a common base class which captures those data and methods. =Example= [[Image:1 before.png...) |
BenMcDonald (Talk | contribs) |
||
Line 1: | Line 1: | ||
− | If two or more classes have common data and | + | :''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= | =Example= | ||
− | [[Image: | + | [[Image:RH5.10Before.png]] |
The two classes Dog and Bird have common data (weight) and behaviour (eat() and sleep()). | The two classes Dog and Bird have common data (weight) and behaviour (eat() and sleep()). | ||
− | [[Image: | + | [[Image:RH5.10After.png]] |
A new class called Animal is created that both Dog and Bird inherit. | A new class called Animal is created that both Dog and Bird inherit. |
Revision as of 04:05, 22 July 2009
- 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.