Java Reference
In-Depth Information
subclass of Sparkler . (A sparkler is a wire coated with a combustible paste saturated with
iron filings that do, in fact, sparkle.)
Other errors are subtler and, as such, subject to judgment as to whether they are in fact errors.
CHALLENGE 26.4
List three aspects of the Figure 26.5 model that are problems or at least questionable.
Figure 26.5. What's at least questionable with this picture?
The Liskov Substitution Principle
New classes should be logical, consistent extensions of their superclasses, but what does it
mean to be logical and consistent? A Java compiler will ensure a certain level of consistency,
but many principles of consistency will elude a compiler. One principle you should consider
in your designs is the Liskov Substitution Principle (LSP). This principle, documented in
Liskov (1987), can be paraphrased: An instance of a class should function as an instance of its
superclass.
Basic LSP compliance is built into OO languages, such as Java. For example, it is legal to
refer to a Rocket object as a Firework , as Rocket is a subclass of Firework :
Firework f = new Rocket();
Search WWH ::




Custom Search