Liskov Principle
Start course

This course looks at the five SOLID principles starting with a little bit of their history before moving on to cover each principle in more detail.

Learning Objectives

  • Learn about the five SOLID principles:
    • Single Responsibility
    • OpenClosed
    • Liskov Principle
    • Interface Segregation
    • Dependency Inversion

Intended Audience

This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java EE.


Basic knowledge of Java programming.


Hello dear friends. In this video, we will examine the Liskov Substitution Principle. So, let's begin. The Liskov Substitution Principle (LSP) named for and originally defined by Barbara Liskov states that we should be able to treat a child class as though it were the parent class. Essentially, this means that all derived classes should retain the functionality of their parent class and cannot replace any functionality the parent provides. The LSP is very similar in principle to the OpenClosed principle. Now let's see with an example. As you see in this image, we have a base rectangle class and in the second image we try to extend square from the rectangle. 

Look, with super method we try to assign length to height or height to length. With this method, we can also extend triangle from rectangle. In that case, only we will set width to the triangle edge. Actually, we can make this but it does not comply with the Liskov Substitution Principle. Therefore, we need to make a new design in accordance with the Liskov Substitution Principle. First, we have to find an abstract class or interface a shape because square and rectangle are both shapes. Now we can create our rectangle from shape like this. As you can see, we have to override calculate area method and for square, we will add another class from shape like this, and we have to overwrite calculate for square again. Now this structure conforms to the Liskov principle. That's all I have to say about LSP. In the following video, we will look at the interface segregation principle. See you in the following video.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.

Covered Topics