C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
Java
Learn iOS Programming
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
3
Reply
What is Liskov Substitution Principle?
Dennis Thomas
7y
7.7k
4
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
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.
Dennis Thomas
7y
2
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.
Rakesh Jogani
7y
1
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)
Devendra Nagayach
7y
1
Message