Understanding LSP in OOP
Explore the Liskov Substitution Principle to understand how to design object-oriented classes that can be safely substituted for their base types without unexpected behavior. Learn why respecting interface contracts matters and how improper subclassing can lead to bugs, using Java examples to guide proper application of this SOLID principle within test-driven development.
We'll cover the following...
Significance of LSP in OOP
Turing Award winner Barbara Liskov is the creator of a rule concerning inheritance that’s now commonly known as LSP. It was brought about by a question in OOP:
If we can extend a class and use it in place of the class we extended, how can we be sure the new class will not break things?
We’ve seen in the previous section on DIP how we can use any class that implements an interface in place of the interface itself. We ...