The Liskov Substitution Principle (LSP) is the SOLID design principle, associated with Barbara Liskov and Robert C. Martin, that subtypes must be substitutable for their base types without altering the correctness of the program. Derived classes must honour the contracts of their base classes. Violations show up as subclass overrides that break expected behaviour, as type checks in client code, or as hierarchies that break the is-a relationship.
SOLID-Liskov Substitution Principle
Details
- Full Name
-
SOLID Liskov Substitution Principle (LSP)
Intent:
Subtypes must be substitutable for their base types without altering the correctness of the program. Derived classes must honor the contracts of their base classes.
When to Use:
-
Subclass overrides break expected behavior of the base class
-
instanceof/type checks appear in client code
-
Inheritance hierarchies violate "is-a" relationships
Prompt Example:
"Überprüfe diese Vererbungshierarchie auf Verletzungen des SOLID-Liskov Substitution Principle."
Related Anchors:
-
SOLID Principles (Umbrella)