educative.io

LISKOV substitution principle

In the course it is mentioned that - "Car is substitutable with its superclass, Motorized, and Bicycle is substitutable with its superclass, Manual, without breaking the functionality."

Is this mean I can use the Car class instead of Motorized or is it the opposite?

TIA


Course: Grokking the Low Level Design Interview Using OOD Principles - Learn Interactively
Lesson: SOLID: Liskov Substitution Principle

Hi @Joydeep_Ballabh

I hope everything is going well with you. Thank you for reaching out about this.

The statement " Car is substitutable with its superclass, Motorized , and Bicycle is substitutable with its superclass, Manual , without breaking the functionality." indicates that you can use an instance of the subclass (Car) wherever an instance of the superclass (Motorised) is expected by the Liskov Substitution Principle (LSP) without affecting the program’s correctness. This is because a Car can be substituted for a superclass Motorized.

Similarly, you can use an instance of the Bicycle class wherever the superclass Manual is expected without affecting the program’s correctness. This is because a Bicycle can be substituted for a superclass Manual.

I hope that this guide is helpful. Remember that I am always available via message to help you with any difficulty you might encounter.

Happy Learning :slight_smile: