Understanding LSP in OOP

Understand how LSP ensures any subclass can be safely used instead of its parent class, adhering to the same expected behaviors, without having unexpected side effects or violations.

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 also saw how those classes can provide any implementation they like for that method. The interface itself provides no ...

Get hands-on with 1400+ tech skills courses.