Heuristics for Subclassing - Construction

A new class can sometimes inherit almost all of its desired functionality from an existing class, even if they share no relationship as abstract ideas. For example, suppose you have an existing List abstraction, and you want to build a new Set data type. You might be tempted to use inheritance, since most of the behavior for the two ideas is similar.

This is termed subclassing for construction. However tempting it might be, it is generally considered to be a bad idea. this is because the child and the parent class will often not share the principle of substitutability, that is, you can not substitute an instance of the child class where an instance of the parent class is expected.

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