Heuristics for Subclassing - Limitation

Subclassing for limitation occurs when you want to explicitly remove some feature you inherit from your parent.

For example, suppose again that you have an existing List data abstraction, and you want to build a Stack. A stack only permits elements to be added or removed from one end, while a list permits additions anywhere in the structure.

One approach would be to override those methods that allow more general access, and make then produce error messages instead. Thus, the only way your new component could be used would be as you wanted.

This is, of course, not generally a good idea, as it once again breaks the principle of substitutability.

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