Introduce common base class

From CSSEMediaWiki
Revision as of 03:55, 22 July 2009 by BenMcDonald (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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

File:1 before.png

The two classes Dog and Bird have common data (weight) and behaviour (eat() and sleep()).

File:2 after.png

A new class called Animal is created that both Dog and Bird inherit.

See also

Personal tools