Liskov Substitution

Domain: Design Principles

🎯 Motivation

Subtypes must be replaceable for their base types without breaking the program. If a subclass changes behavior unexpectedly, code that relies on the parent class will fail in confusing ways.

πŸ“‹ Concrete Example

If Bird has a fly() method, then Penguin should not inherit Bird directly. A penguin that throws an error on fly() violates substitution, so restructure the hierarchy.

πŸ”— Analogy

If you order a β€œvehicle” and receive a bicycle, you can still ride it to school. But if you receive a toy car that cannot move, the promise is broken β€” substitution failed.