DEV Community

Discussion on: Liskov Substitution Principle

Collapse
 
vampiire profile image
Vamp

is this different from polymorphism?

i see an opportunity for using interfaces rather than inheritance. Unless LSP is strictly about class inheritance (but that seems contrived since interfaces in Java are effectively just classes with extra constraints to regulate their single inheritance model).

if they are the same then an interface Flyable implemented by flying birds (base class has eat) would work. the Main letBirdsFly method can be letFly and accept a list of Flyable (extending ability to let any flying object be invoked, even beyond birds).

Collapse
 
amrsaeedhosny profile image
Amr Saeed

Polymorphism is an object-oriented programming concept. This principle is a design principle which uses the OOP concepts such as Polymorphism to achieve a cleaner software design (Object-Oriented Design).

You can use normal classes, abstract ones, or interfaces. The principle isn't stricted to any type of them. Actually I used inheritance for simplicity, as there are many languages that don't support interfaces. You can use interfaces if u won't create objects from the parents, but if it's not the case use normal classes and inheritance.

You have to know that it doesn't change the way the principle is applied.

Collapse
 
vampiire profile image
Vamp

thanks for the thorough response. i hadn’t heard of the LSP before but understood its application in polymorphism.

and thank you for the series it was well written.