0
0
LLDsystem_design~10 mins

Factory Method pattern 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 declare the Factory Method in the Creator class.

LLD
abstract class Creator {
    abstract [1] createProduct();
}
Drag options to blanks, or click blank then click option'
Avoid
BProduct
Cint
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using void as return type which means no object is returned.
Using primitive types like int or String which are unrelated.
2fill in blank
medium

Complete the code to implement the Factory Method in the ConcreteCreator class.

LLD
class ConcreteCreator extends Creator {
    @Override
    public [1] createProduct() {
        return new ConcreteProduct();
    }
}
Drag options to blanks, or click blank then click option'
AConcreteProduct
Bvoid
CProduct
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using ConcreteProduct as return type breaks abstraction.
Using void or primitive types causes compile errors.
3fill in blank
hard

Fix the error in the client code that uses the Factory Method to get a product.

LLD
Creator creator = new ConcreteCreator();
Product product = creator.[1]();
product.use();
Drag options to blanks, or click blank then click option'
AcreateProduct
BmakeProduct
CgetProduct
DnewProduct
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names not declared in Creator causes compile errors.
Trying to instantiate product directly instead of using factory method.
4fill in blank
hard

Fill both blanks to complete the product interface and its concrete implementation.

LLD
interface [1] {
    void [2]();
}

class ConcreteProduct implements Product {
    public void use() {
        System.out.println("Using ConcreteProduct");
    }
}
Drag options to blanks, or click blank then click option'
AProduct
Buse
Cexecute
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using different interface names breaks the pattern.
Method names that don't match cause implementation errors.
5fill in blank
hard

Fill all three blanks to complete the Creator class with a factory method and a business logic method.

LLD
abstract class Creator {
    public abstract [1] createProduct();

    public void [2]() {
        [3] product = createProduct();
        product.use();
    }
}
Drag options to blanks, or click blank then click option'
AProduct
Boperate
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching return and variable types causes errors.
Using incorrect method names breaks the pattern.