Heuristics and Conventions
Some simple heuristics can give you some clues about LSP violations. These heuristics all have to do with derivative classes that somehow
functionality from their base classes. A derivative that does less than its base is usually not substitutable for that base and therefore
Consider Figure 10-13. The
is implemented but in
Listing 10-13. A degenerate function in a derivative
The presence of degenerate functions in derivatives is not always indicative of an LSP violation, but it's worth looking at them when they occur.
The Open/Closed Principle is at the heart of many of the claims made for object-oriented design. When this principle is in effect, applications are more
[Liskov88] "Data Abstraction and Hierarchy," Barbara Liskov, SIGPLAN Notices , 23(5) (May 1988).
[Meyer97] Bertrand Meyer, Object-Oriented Software Construction , 2d. ed., Prentice Hall, 1997.
[Wirfs-Brock90] Rebecca Wirfs-Brock et al. , Designing Object-Oriented Software , Prentice Hall, 1990.
Chapter 11. The Dependency-Inversion Principle (DIP)
Jennifer M. Kohnke
Consider the implications of high-level modules that depend on low-level modules. It is the high-level modules that contain the important policy decisions and business models of an application. These modules contain the identity of the application. Yet when these modules depend on the lower-level modules, changes to the lower-level modules can have direct effects on the higher-level modules and can force them to change in
This predicament is absurd! It is the high-level, policy-setting modules that ought to be influencing the low-level detailed modules. The modules that contain the high-level business rules should take precedence over, and be independent of, the modules that contain the implementation details. High-level modules simply should not depend on low-level modules in any way.
Moreover, it is high-level, policy-setting modules that we want to be able to reuse. We are already quite good at reusing low-level modules in the form of subroutine libraries. When high-level modules depend on low-level modules, it becomes very difficult to reuse those high-level modules in different contexts. However, when the high-level modules are independent of the low-level modules, the high-level modules can be reused quite simply. This principle is at the very heart of framework design.