0
0
LLDsystem_design~10 mins

Why SOLID principles guide maintainable design in LLD - Test Your Understanding

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

Complete the code to apply the Single Responsibility Principle (SRP) by defining a class that only handles user data storage.

LLD
class UserDataHandler:
    def __init__(self, user):
        self.user = user
    def [1](self):
        # Save user data to database
        pass
Drag options to blanks, or click blank then click option'
Ahandle_all_tasks
Bsend_email
Cprocess_payment
Dsave_user_data
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a method name that does multiple unrelated tasks.
2fill in blank
medium

Complete the code to follow the Open/Closed Principle by allowing new payment methods without changing existing code.

LLD
class PaymentProcessor:
    def process(self, payment_method):
        if payment_method == 'credit_card':
            self.process_credit_card()
        elif payment_method == 'paypal':
            self.process_paypal()
        # To add new methods, use [1] instead of if-else
Drag options to blanks, or click blank then click option'
Ahardcoding
Bpolymorphism
Cglobal variables
Dmonolithic design
Attempts:
3 left
💡 Hint
Common Mistakes
Using if-else statements that require code changes for new methods.
3fill in blank
hard

Fix the error in the code to respect the Liskov Substitution Principle by ensuring the subclass can replace the superclass without issues.

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

class Penguin(Bird):
    def [1](self):
        print('Penguins swim!')
Drag options to blanks, or click blank then click option'
Afly
Bswim
Cwalk
Dsing
Attempts:
3 left
💡 Hint
Common Mistakes
Raising exceptions in overridden methods that are expected to work.
4fill in blank
hard

Fill both blanks to apply Interface Segregation Principle by splitting a large interface into smaller ones.

LLD
class [1]:
    def read(self): pass
    def write(self): pass

class [2]:
    def print(self): pass
Drag options to blanks, or click blank then click option'
AReadable
BWritable
CPrinter
DDocument
Attempts:
3 left
💡 Hint
Common Mistakes
Combining unrelated methods into one interface.
5fill in blank
hard

Fill all three blanks to apply Dependency Inversion Principle by depending on abstractions, not concrete classes.

LLD
class [1]:
    def connect(self): pass

class DatabaseConnection([2]):
    def connect(self):
        print('Connected to DB')

class Application:
    def __init__(self, db: [3]):
        self.db = db
Drag options to blanks, or click blank then click option'
AIDatabase
BDatabaseConnection
DConcreteDatabase
Attempts:
3 left
💡 Hint
Common Mistakes
High-level classes depending directly on concrete classes.