简体   繁体   中英

liskov substitution principle again - each method overriding violates the principle

I know there is many similar subjects but I need to ask because the rule is "If class S is a subtype of class T, then instances of T may be replaced by instances of S without altering any of the desirable behaviors of T itself." - so each method overriding violates the rule. Am I wrong? Because each method overriding alters base class. If not - please give the example.

At first, you need to understand concept of abstraction and polymorphism in OOP.

If T is parent class, it should be overridden by child class S given that T is made virtual and S override. Example: T can be BirdClass() with CanFly(), CanEat(), CanSee() methods. Then S can be Pegion that can override CanFly(), CanEat(), CanSee() methods. OR Sparrow that can override CanFly(), CanEat(), CanSee() methods of parent class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM