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.
Asked
Active
Viewed 75 times
1
-
1Possible duplicate of [Liskov substitution principle - no overriding/virtual methods?](https://stackoverflow.com/questions/1735137/liskov-substitution-principle-no-overriding-virtual-methods) – sr28 Jun 27 '19 at 11:03
-
Possible duplicate of [Overriding without calling parent method, violating Liskov Principle](https://stackoverflow.com/questions/48046418/overriding-without-calling-parent-method-violating-liskov-principle) – Pribina Jun 27 '19 at 11:03
-
Yes, you are wrong. https://stackoverflow.com/questions/56330262/what-does-liskov-substitution-principle-preserve/56335193#56335193 – Matt Timmermans Jun 28 '19 at 04:09
1 Answers
1
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.

CodesDDecodes
- 132
- 1
- 15