![]() ![]() If you look at the above classes, Ostrich is not a bird. can't implement fly since Ostrich doesn't fly Let’s take a simple look before we look at this in detail. If you want to learn more about Object-Oriented Design, get this course from educative. Any of the objects that fail to follow the contract, will violate the Liskov Substitution Principle. Any inherited object from this superclass or interface implementation class must follow the contract. Usually, when you define a superclass or an interface, it is a contract. LSP comes into play when you have super-sub class OR interface implementation type of inheritance. Wikipedia definition says – If S is a subtype of T, then the objects of type T may be replaced with objects of S without altering any of the desirable properties of the program. Liskov Substitution Principle (LSP)īasically, the principle states that if in an object-oriented program you substitute superclass object reference with any of its subclass objects, it should not break the program. Let’s start with the basics of Liskov Substitution Principle first. You can learn more about other object oriented design principles. Hopefully, you will be able to use this in your design and find out if there are any violations. This is a key principle to validate the object-oriented design of your system. In this post, I will cover the details of the Liskov Substitution Principle(LSP) with an example.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |