The IS-a Rule

When is the use of inheritance appropriate? There is a rule-of-thumb that is commonly used to answer this question. this is called the is-a rule.

The idea is that if you are trying to determine if a concept A should be formed using inheritance from an existing concept B, try forming the sentence ``an A is-a B''. The result sounds right to your ear, then in most cases A is an appropriate subclass of B.

For example, saying that a dog is-a mammal sounds right, therefore it would be approrpaite to make the class Dog inherit from class Mammal.

On the other hand, saying that a car is-a engine sounds wrong, and therefore inheritance would probably not be appropriate. But a car has-an engine, so there is some connection between the two concepts, just not inheritance.

[audio] [real] Text to accompany slidexx, in Chapter 8 of An Introduction to Object-Oriented Programming