DEV Community

loading...

Discussion on: Is The Liskov Substitution Principle Really Useful?

Collapse
jexperton profile image
Jonathan Experton • Edited

I might misunderstand the Liskov substitution principle but here's how I would read it:

Replacing an instance of a class with any other class that extends the same parent class should not produce any negative side effects or broken codebase.

In other words:

Classes that share the same interfaces (contracts) should be interchangeable.

This is a condition to polymorphism and therefore a condition to the open-close principle and a way to avoid writing rigid softwares.

It also relates to the Interface Segregation principle as you don't want to bloat your classes with useless contracts that just prevent the interchangeabilility.

I admit the original definition is cryptic to me and not very useful.

Forem Open with the Forem app