MrChudz
MrChudz

Reputation: 1205

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.

Upvotes: 1

Views: 89

Answers (1)

CodesDDecodes
CodesDDecodes

Reputation: 132

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.

Upvotes: 1

Related Questions