0
0
LLDsystem_design~10 mins

Composition over inheritance 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 define a class that uses composition to include a Logger component.

LLD
class Application:
    def __init__(self):
        self.logger = [1]()
Drag options to blanks, or click blank then click option'
ALogger
BInheritance
CComponent
DInterface
Attempts:
3 left
💡 Hint
Common Mistakes
Using inheritance keyword instead of creating an instance.
2fill in blank
medium

Complete the code to delegate the log message to the composed Logger object.

LLD
class Application:
    def __init__(self):
        self.logger = Logger()
    def log(self, message):
        self.logger.[1](message)
Drag options to blanks, or click blank then click option'
Alog
Bwrite
Cprint
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist in Logger.
3fill in blank
hard

Fix the error in the code to properly use composition instead of inheritance.

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

class Application([1]):
    def __init__(self):
        self.logger = Logger()
Drag options to blanks, or click blank then click option'
AApplication
BLogger
Cobject
DComponent
Attempts:
3 left
💡 Hint
Common Mistakes
Inheriting from Logger instead of using it as a component.
4fill in blank
hard

Fill both blanks to complete the code that shows composition with two components.

LLD
class Application:
    def __init__(self):
        self.logger = [1]()
        self.database = [2]()
Drag options to blanks, or click blank then click option'
ALogger
BDatabase
CComponent
DService
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic names instead of actual component classes.
5fill in blank
hard

Fill all three blanks to complete the code that delegates methods to composed components.

LLD
class Application:
    def __init__(self):
        self.logger = Logger()
        self.database = Database()
    def log(self, message):
        self.logger.[1](message)
    def save(self, data):
        self.database.[2](data)
    def load(self, id):
        return self.database.[3](id)
Drag options to blanks, or click blank then click option'
Alog
Bsave
Cload
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names that do not exist in components.