Interviews - C# Corner

Dennis Thomas
What is Liskov Substitution Principle?
By Dennis Thomas in OOP/OOD onDec 18 2017
  • Dennis Thomas
    Dec, 2017 18

    Objects in a program should be replaceable with instances of their sub types without altering the correctness of that program. That means, the derived classes should only extend the functionality of the base class. Then, we will be able to substitute the object of the parent class with the object of the derived class.

    • 2
  • Devendra Nagayach
    Feb, 2018 23

    Derived types must be completely substitutable for their base types. Ex- consider employee is a base class and permanent employee and temporary employee are child class.no new exception can be throw by sub type(child class)

    • 1
  • Rakesh Jogani
    Aug, 2018 29

    The Liskov Substitution Principle (LSP) states that "you should be able to use any derived class instead of a parent class and have it behave in the same manner without modification". It ensures that a derived class does not affect the behaviour of the parent class, in other words, that a derived class must be substitutable for its base class.This principle is just an extension of the Open Close Principle and it means that we must ensure that new derived classes extend the base classes without changing their behaviour. I will explain this with a real world example that violates LSP.A father is a doctor whereas his son wants to become a cricketer. So here the son can't replace his father even though they both belong to the same family hierarchy.

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS