What does the Liskov Substitution Principle (LSP) mean?

Answer

The Liskov Substitution Principle, formulated by Barbara Liskov, states that objects of a subclass must be replaceable by objects of the parent class without breaking the program's correctness. If you have a function that accepts a Bird object and calls bird.fly(), and you pass a Penguin subclass that throws an exception on fly(), you violate LSP. A classic example: a Square that extends Rectangle might violate LSP because setting width on a Square also changes height, breaking the rectangle's behavior contract. LSP ensures that inheritance hierarchies are behaviorally consistent, not just structurally similar.