0
0
LLDsystem_design~10 mins

Why structural patterns organize class relationships 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 define a structural pattern that connects classes.

LLD
class Adapter:
    def __init__(self, adaptee):
        self.adaptee = adaptee

    def request(self):
        return self.adaptee.[1]()
Drag options to blanks, or click blank then click option'
Aunrelated_method
Bgeneral_request
Cspecific_request
Dundefined_method
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist in the adaptee.
2fill in blank
medium

Complete the code to show how a decorator adds behavior to a class.

LLD
class Component:
    def operation(self):
        return "Component operation"

class Decorator(Component):
    def __init__(self, component):
        self.component = component

    def operation(self):
        return self.component.operation() + [1]
Drag options to blanks, or click blank then click option'
A" with added behavior"
Bself.component.operation()
C" base behavior"
Dself.operation()
Attempts:
3 left
💡 Hint
Common Mistakes
Calling self.operation() recursively causing infinite loop.
3fill in blank
hard

Fix the error in the composite pattern code to correctly add child components.

LLD
class Composite:
    def __init__(self):
        self.children = []

    def add(self, component):
        self.children.[1](component)
Drag options to blanks, or click blank then click option'
Aadd
Bappend
Cinsert
Dextend
Attempts:
3 left
💡 Hint
Common Mistakes
Using add which is not a list method in Python.
4fill in blank
hard

Fill both blanks to complete the proxy pattern that controls access to a resource.

LLD
class Proxy:
    def __init__(self, real_subject):
        self.real_subject = real_subject

    def request(self):
        if self.check_access():
            return self.real_subject.[1]()
        else:
            return [2]
Drag options to blanks, or click blank then click option'
Arequest
B"Access denied"
CNone
Dcheck_access
Attempts:
3 left
💡 Hint
Common Mistakes
Returning None instead of an access denied message.
5fill in blank
hard

Fill all three blanks to complete the flyweight pattern that shares objects efficiently.

LLD
class FlyweightFactory:
    def __init__(self):
        self._flyweights = {}

    def get_flyweight(self, key):
        if key not in self._flyweights:
            self._flyweights[[1]] = Flyweight([2])
        return self._flyweights[[3]]
Drag options to blanks, or click blank then click option'
Akey
C"new_key"
DFlyweight
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys for storing and retrieving flyweights.