Sample chapter: The Liskov Substitution Principle

The Liskov substitution principle (LSP) is a collection of guidelines for creating inheritance hierarchies in which a client can reliably use any class or subclass without compromising the expected behavior. This chapter from Adaptive Code via C#: Agile coding with design patterns and SOLID principles explains what the LSP is and how to avoid breaking its rules.

After completing this chapter, you will be able to

  • Understand the importance of the Liskov substitution principle.
  • Avoid breaking the rules of the Liskov substitution principle.
  • Further solidify your single responsibility principle and open/closed principle habits.
  • Create derived classes that honor the contracts of their base classes.
  • Use code contracts to implement preconditions, postconditions, and data invariants.
  • Write correct exception-throwing code.
  • Understand covariance, contravariance, and invariance and where each applies.

Find the complete chapter here:

Skip to main content