Understanding Liskov Substitution Principle(LSP)
Lets Look at the below example:
Car and biCycle are both Vehicle but , biCycle can’t substitute vehicle because biCycle does not have an engine.
Solving above according to LISKOV Substitution Principal:
Vehicle is a generalization for Motorized and Non Motorized Vehicle.
Now Both Car and BiCycle can replace the super class and interfaces
Now Let’s Look at the Liskov Substitution Principle (LSP)
The Liskov Substitution Principle (LSP), named after Barbara Liskov, is one of the five SOLID principles of object-oriented design and programming. It formalizes a foundational concept for creating class hierarchies that are interchangeable without altering the correctness of the program.
Principle Definition
LSP states that objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program. In other words, if class B is a subclass of class A, then we should be…