Lesson 3: LSP and behavioral contracts
You swapped one implementation for another — and the system crashed, even though the compiler was perfectly happy. For example: a PreviewExporter that looks like an Exporter in every way, but throws an exception precisely on the large lists production uses. This lesson teaches the Liskov Substitutio
LSP is like spare batteries: every AA battery must work in every device built for AA. A battery that fits the slot but fries the remote broke the promise.
- Liskov Substitution Principle (LSP)
- Every subtype must work anywhere its base type is expected — with no surprises for the caller.
- behavioral contract
- A method's promises beyond its signature: which inputs are valid, what the output guarantees, and which errors may occur.