Liskov Substitution Principle

Noun · Development

Definitions

  1. The 'L' in SOLID: a subtype must be substitutable for its base type without altering the correctness of the program. Concretely, if code works with a base class, it must also work with any derived class — meaning subtypes must honor the base type's contracts, preconditions, postconditions, and invariants.

    In plain English: A design rule that says if you swap in a more specific version of something, the program should still work correctly without surprises.

    Example: "Your Square class violates the Liskov Substitution Principle because setting width on a Rectangle shouldn't silently change height."

Related Terms