SOLID Principles

Liskov Substitution Principle (LSP)

The Liskov Substitution Principle states that objects of a superclass should be replaceable with objects of a subclass without affecting the correctness of the program. In other words, if S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of the program (correctness, task performed, etc.).

Benefits:

  • Ensures that derived classes are properly implementing the behavior expected from the base class.
  • Promotes the use of polymorphism correctly.
  • Enhances code reliability and robustness.