0
0
LLDsystem_design~10 mins

Liskov Substitution Principle in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to ensure the subclass can replace the superclass without errors.

LLD
class Bird:
    def fly(self):
        print("Flying")

class [1](Bird):
    def fly(self):
        print("Flying high")
Drag options to blanks, or click blank then click option'
AEagle
BPenguin
COstrich
DFish
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a subclass that cannot perform the superclass's behavior (like Penguin).
Using a non-bird class as subclass.
2fill in blank
medium

Complete the method to follow Liskov Substitution Principle by not throwing unexpected exceptions.

LLD
class Rectangle:
    def set_width(self, width):
        self.width = width

class Square(Rectangle):
    def set_width(self, width):
        if width < 0:
            raise ValueError("Width must be positive")
        self.width = width

    def set_height(self, height):
        if [1]:
            raise ValueError("Height must be positive")
        self.width = height
Drag options to blanks, or click blank then click option'
Aheight > 0
Bheight == 0
Cheight < 0
Dheight != 0
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for positive values instead of invalid negative values.
Not validating input leading to inconsistent behavior.
3fill in blank
hard

Fix the error in the subclass method to respect Liskov Substitution Principle by matching the superclass method signature.

LLD
class Vehicle:
    def start(self, key):
        print("Vehicle started")

class Car(Vehicle):
    def start(self, [1]):
        print("Car started")
Drag options to blanks, or click blank then click option'
Akey
Bengine
Cignition
Dstart_key
Attempts:
3 left
💡 Hint
Common Mistakes
Renaming parameters in subclass methods.
Adding or removing parameters in subclass methods.
4fill in blank
hard

Fill both blanks to ensure the subclass method signature and behavior follow Liskov Substitution Principle.

LLD
class PaymentProcessor:
    def process_payment(self, amount):
        pass

class CreditCardProcessor(PaymentProcessor):
    def [1](self, [2]):
        print(f"Processing credit card payment of {amount}")
Drag options to blanks, or click blank then click option'
Aprocess_payment
Bamount
Cpay
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using different method names in subclass.
Changing parameter names or count.
5fill in blank
hard

Fill all three blanks to correctly implement a subclass that respects Liskov Substitution Principle by maintaining method signature and behavior.

LLD
class Logger:
    def log(self, message):
        print(message)

class FileLogger(Logger):
    def [1](self, [2]):
        with open('log.txt', 'a') as f:
            f.write([3] + '\n')
Drag options to blanks, or click blank then click option'
Alog
Bmessage
Dmsg
Attempts:
3 left
💡 Hint
Common Mistakes
Changing method or parameter names.
Not using the parameter in the method body.