Liskov Substitution Principle (LSP)

Subtypes must be substitutable for their base types.

This principle supports the below scenario-
   Suppose a method takes parent type and perform some operation on it.
   And the subtype is not of type - parent but still wrongly inherits the parent. 
      If the above subtype object is passed to such method, the operation performed will be weird as the method assumes it is suppose to be parent type.

Hence, a class should inherit parent only if its of that type. (eg: Square is not Rectangle programmatically as the area is always side^2) 

Comments

Popular posts from this blog

@Overrride annotation introduced in Java1.5

Interface Segregation Principle