9LSP: THE LISKOV SUBSTITUTION PRINCIPLE
In 1988, Barbara Liskov wrote the following as a way of defining subtypes.
What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T.1
To understand this idea, which is known as the Liskov Substitution Principle (LSP), let’s look at some examples.
GUIDING THE USE OF INHERITANCE
Imagine that we have a class named
License, as shown in Figure 9.1. This class has a method named
calcFee(), which ...