Let f(objMainClass) be a property provable about objects objMainClass of type MainClass. Then f(objSublass) should be provable for objects objSublass of type SubClass where SubClass is a subtype of MainClass.

The Liskov Substitution Principle (LSP) states that Liskov Substitution subtypes must be substitutable for their base types.

"Is-Substitutable-For" Not Just "Is-A" 

  • You should be able to substitute child types for their base types anywhere you need to work with them.
  • This means that you can write methods that accept a base type as a parameter, and they can work with that base type's methods and properties, regardless of what actual child implementation of that base class is passed as an argument. 

 
This principle is just an extension of the Open Close Principle. 
It means that we must make sure that new derived classes are extending the base classes without changing their behavior.


Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.
 
 Or 
  
If any module is using a Base class then the reference to that Base class can be replaced with a Derived class without affecting the functionality of the module.
 

Or
 
While implementing derived classes, need to ensure that the derived classes just extend the functionality of base classes without replacing the functionality of base classes.

 

Reference Example