Grokking SOLID Design Principles
Ask Author
Back to course home

0% completed

Vote For New Content
Keshav Garg
Is this a valid example?

Keshav Garg

Oct 27, 2024

The Liskov Substitution Principle (LSP) is a fundamental principle in object-oriented programming that states that objects of a superclass should be able to be replaced with objects of a subclass without affecting the correctness of the program.

This ensures that the Liskov Substitution Principle is followed: an instance of ElectricCar can replace Car without causing issues.

 We didn't replace superclass object with subclass object in this case. We just replace it with another subclass object?

2

0

Comments
Comments
H
htsondk251 10 months ago

After refactoring,

the child classes (Car or ElectricCar) can substitute for the parent class (Vehicle) without causing errors, which adheres to the LSP.

On this page