Posted by : Sushanth Thursday, 17 December 2015

Functions that use references to base classes must be able to use objects of derived classes with out knowing it.
LSP Violation:

Class Product
{
Private :
String name;
String Author;
Public:
string getName();
setName(string name);
string getAuthor();
setAuthor(string author);
};
Class book : public product
{
};
Class movie:public product
{
};
If a author is queried with a product object which is actually a movie object ,the resulting behavior is not correct as the movie doesn’t have any author.
LSP:
Using derived classes should not end up in unexpected results when using derived classes.
The "Liskov's Substitution Principle" is just a way of ensuring that inheritance is used correctly.

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Technical Articles - Skyblue - Powered by Blogger - Designed by Johanes Djogan -