![]() ![]() That sounds simple enough, but there is more than meets the eye. If S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of the program. More simpler definitions have arisen since the original paper and they go as: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T. Originally written by Barbara Liskov, It states: Generally, a piece of code that breaks the Liskov Substitution Principle also breaks the Open-Close principle. However, it is not so straight forward to identify when the code is breaking the principle. The Liskov Substitution Principle is a simple yet effective way to improve the code. But what differentiates a good inheritance structure from a bad one? That is where the Liskov Substitution Principle comes into play. ![]() introduce new classes for new functionality and keep the classes related to existing functionality untouched. The primary idea behind the Open-Closed principle is achieved using inheritance i.e. In this post, I will take you through the L in SOLID, the Liskov Substitution Principle. This is the third in the series of posts on SOLID Software Principles. We previously covered the Single Responsibility Principle and the Open-Close Principle. SOLID: Liskov Substitution Principle SoftwareYoga
0 Comments
Leave a Reply. |