Reuse of Code, Reuse of Concept

why do we use inheritance? There are a number of pratical reasons (some of which we will summarize shortly), but if we step back and look at the larger picture, there are basically two main motivations.

The first is the reuse of code. this occurs when a child class inherits methods from the parent. The child therefore gets this behavior for free. This allows code to be written once and reused in many different classes.

The second reason can be termed reuse of concept. This occurs when a child class overrides a method in the parent. No code is therefore being shared, but nevertheless there is a link. It is the concept of the behavior being shared between parent and child. We saw and example of this in the billiards case study, when we defined that all graphical objects new how to respond to the method draw.

Where OOP becomes most powerful is when these two different types of use are mixed together.

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