Liskov Substitution Principle

Taylan Can Hardal
2 min readFeb 21, 2022

--

Hey everybody it is third principle of SOLID Principles. This means that every subclass or derived class should be substitutable for their base or parent class.
So every base class should be able to interchange with subclasses.

Let’s say there is a person class and 3 derived classes from the person class. Baby, young and adult. These classes have some functions such as Breath, Blink, GoWork but there is an error. Babies can’t go to work. So we have to change our architecture. Let’s learn with project.

Example Project

In order to learn in detail, the correct usage and the wrong usage should be examined together.

Wrong Usage :

As we said, babies can’t go to work. Our Person class is wrong. So functions must be Interfaces and we implement these interfaces in our classes.

Correct Usage :

We split this class into two and keep the functions in a class called Actions and the other classes in the Person class. We have solved our problem by implementing the functions we have included in the interface into the classes.

You can continue reading here :

References:

bolŞans…

--

--

Taylan Can Hardal
Taylan Can Hardal

Written by Taylan Can Hardal

Software Engineer @Turkcell. Savin’ the Earth. Somewhere

No responses yet