Introduction to OOP: Chapter 7: Inheritance [next] [previous] [audio] [real] [text]

The Is-a and Has-a rules

Our idealization of inheritance is captured in a simple rule-of-thumb.

Try forming the English sentences ``An A is-a B''. If it ``sounds right'' to your ear, then A can be made a subclass of B.

A dog is-a mammal, and therefore a dog inherits from mammal

A car is-a engine sounds wrong, and therefore inheritance is not natual. but a car has-a engine.

Intro OOP, Chapter 7, Slide 5a