Published October 26, 2019
by Doug Klugh
Maintaining the Constraints of Inheritance
Build classes in such a way that a derived class can always replace its base class without changing behavior or side effects of the base class. The derived class can do more than its base class, but must never do less. This principle governs inheritance, polymorphism, and subtyping. LSP violations may be discovered through degenerate functions, derived methods that do nothing but throw exceptions, or methods that type-check instances of objects. While these are not always LSP violations, they are strong indicators of such. And keep in mind, every LSP violation is a latent OCP violation.
This principle is based on a requirement that constrains the behavior of subtypes and is formally described as:
Let φ(x) be a property provable about objects x of type T. Then φ(y) should be true for objects y of type S where S is a subtype of T.
The Liskov Substitution Principle was named for a formal definition of subtyping called Strong Behavioral Subtyping. It was introduced in 1987 by Barbara Liskov as the Keynote Speaker at the ACM OOPSLA conference in Orlando, Florida — in a keynote address titled Data Abstraction and Hierarchy.
Barbara, an Institute Professor at MIT, developed this definition with Jeannette Wing, who at the time was a Professor of Computer Science at Carnegie Mellon University.