0
0
LLDsystem_design~10 mins

Why creational patterns manage object creation 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 create an object using a creational pattern.

LLD
object = [1]()
Drag options to blanks, or click blank then click option'
AFactory
BBuilder
CSingleton
DObserver
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing Observer which is for event handling, not creation.
2fill in blank
medium

Complete the code to ensure only one instance of a class is created.

LLD
class Singleton:
    _instance = None

    def __new__(cls):
        if [1] is None:
            cls._instance = super().__new__(cls)
        return cls._instance
Drag options to blanks, or click blank then click option'
Acls.instance
Bcls
Ccls._instance
Dcls._singleton
Attempts:
3 left
💡 Hint
Common Mistakes
Using cls.instance which is not defined.
3fill in blank
hard

Fix the error in the Builder pattern method to return the final product.

LLD
class Builder:
    def __init__(self):
        self.product = []

    def add_part(self, part):
        self.product.append(part)

    def get_result(self):
        return [1]
Drag options to blanks, or click blank then click option'
Aself
Bproduct
Cpart
Dself.product
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 'product' without self causes a NameError.
4fill in blank
hard

Fill both blanks to create a Factory method that returns a new object.

LLD
def factory_method(type):
    if type == 'A':
        return [1]()
    else:
        return [2]()
Drag options to blanks, or click blank then click option'
AProductA
BProductB
CProductC
DProductD
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same product class for both types.
5fill in blank
hard

Fill all three blanks to complete the Singleton pattern implementation.

LLD
class Singleton:
    _instance = None

    def __new__(cls):
        if [1] is None:
            [2] = super().__new__(cls)
        return [3]
Drag options to blanks, or click blank then click option'
Acls._instance
Dcls
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causing errors.