Using Inheritance

If we use inheritance, we need only specify what is new or different. In this case, only the addition method needs to be changed so as to check whether an element is in the collection before it is added. The inclusion test, the removal operation, the method to return the first element in the collection, they will all work as before. So we get a lot of free behavior with very little effort.

Notice that a method can invoke an inherited method, without naming a receiver. We see that in the text for includes. If no receiver is named, it is interpreted as a message sent to yourself.

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