Learn some basic rules you can apply to subclasses and other is a. Based on subtyping polymorphism in an object-oriented language, a derived. Ben and Joe tackle the third principle in SOLID: the Liskov Substitution Principle. All the subclasses of Bird can inherit the properties and methods in the Bird class, so I don’t have to define them again. The Liskov Substitution Principle (LSP) is strongly related to subtyping polymorphism. In the Bird class, i may define common properties such as Age, Name, Feathers, Wings and common behavior such as fly(). For example, I may have a superclass called Bird of which subclasses include Owl and HummingBird. Lets see the mathematical definition of this principle. When used correctly, inheritance can help make codes more concise and easier to maintain. Today, well review the L, which stands for Liskov Substitution, Liskov being the creators name (Barbara Liskov). The Liskov Principle is most applicable when using inheritance. Why should I adhere to the Liskov Substitution Principle? Bringing this idea into programming, the Liskov Substitution Principle states that a subtype should have all the behaviors of the supertype such that you can replace an object of the supertype with an object of the subtype without altering the behaviors of the program. The Liskov Substitution Principle: gives us a way to characterize good inheritance hierarchies, increases our awareness about traps that will cause us to create hierarchies that do not conform to the open-closed principle. So, it would be wrong to say that Penguin is a subtype of flying-bird. In terms of type and subtype, we may say flying-bird is a type of which Owl, HummingBird and other flying birds are subtypes. For example, Owl, Hummingbird and other flying birds share a common behavior and feature which is that they all have wings and can fly. Oxford language dictionary defines a type as “a category of people or things having common characteristics” and subtype as “a secondary or subordinate type”. The Liskov Substitution Principle refers to a property between a type and a subtype. What is the Liskov Substitution Principle? The principle is one out of the five software design principles in SOLID: SOLID stands for : Single Responsibility Principle, Open/Closed Principle, Liskov Substitution Principle, Interface Segregation Principle, and Dependency. In this post, I continue to go over the principle in more details and give examples. That property later becomes known as the Liskov Substitution Principle. In the paper, the author states a property which exists between type and subtype. In the previous post, I wrote about Barbara Liskov research paper on data abstraction and hierarchy.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |