The definition of it might be a bit complex, but in fact, it is quite easy. Imagine a derived class throwing an exception that the superclass does not throw, or if a derived class has some unexpected side effects. In general, if a subtype of the super type does something that the client of the super type does not expect, then this is in violation of LSP. To be a true behavioral subtype, the subclass must not only implement the base class’s methods and properties, but also stick to its implied behavior. The specific functionality of the subclass may be different, but must conform to the expected behavior of the base class. LSP applies to inheritance hierarchies, specifying that you should design your classes so that client dependencies can be substituted with subclasses without the client knowing about the change.Īll subclasses must, therefore, operate in the same manner as their base classes. Basically, derived classes should never do less than their base class. Therefore, a child class should never change the characteristics of its parent class (such as the argument list and return types). In Layman’s terms, it states that an object of a superclass should be replaceable by objects of its subclasses without causing issues in the application. “Derived types must be completely substitutable for their base types” Simply put, if class A is a subtype of class B, then we should be able to replace objects of B with objects of A (i.e., objects of type A may substitute objects of type B) without changing the behavior (correctness, functionality, etc.) of our program. Dependency Inversion Principle(DIP) What is SOLID Principles-The Liskov Substitution Principle?.What is the benefit of Liskov Substitution Principle?.Why is it required to follow Liskov Substitution Principle?.What is SOLID Principles-The Liskov Substitution Principle?.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |