The Is-a and Has-a rules

Our idealized notion of inheritance can be captured in simple rule-of-thumb that can be used to tell whether or not inheritance is an appropriate tool to use in a given situation. Try forming the English sentence ``An A is-a B''. If the sentence ``sounds right'' to your ears, then it is appropriate to form A as a subclass of B. For example, a ``Dog is-a Mammal''.

On the other hand, ``A Car is-a Engine'' sounds odd, not right. Therefore inheritance is probably not appropriate in this situation.

[audio] 5a [real] 5a Text to accompany slide 5a, in Chapter 7 of An Introduction to Object-Oriented Programming