0
0
LLDsystem_design~10 mins

Prototype 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 Prototype interface method for cloning.

LLD
interface Prototype {
    Prototype [1]();
}
Drag options to blanks, or click blank then click option'
AnewInstance
Bclone
Ccopy
Dduplicate
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names like copy or duplicate which are not standard in Prototype pattern.
Forgetting to return the Prototype type.
2fill in blank
medium

Complete the code to implement the clone method in a concrete prototype class.

LLD
class ConcretePrototype implements Prototype {
    private int id;
    ConcretePrototype(int id) {
        this.id = id;
    }
    public Prototype [1]() {
        return new ConcretePrototype(this.id);
    }
}
Drag options to blanks, or click blank then click option'
Acopy
Bduplicate
Cclone
DnewInstance
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than declared in the interface.
Not returning a new instance.
3fill in blank
hard

Fix the error in the clone method to correctly copy the object state.

LLD
public Prototype clone() {
    return new ConcretePrototype([1]);
}
Drag options to blanks, or click blank then click option'
Anew id
Bid
Cprototype.id
Dthis.id
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variables like prototype.id or new id.
Omitting 'this' causing ambiguity.
4fill in blank
hard

Fill both blanks to create a prototype registry and clone an object from it.

LLD
class PrototypeRegistry {
    private Map<String, Prototype> prototypes = new HashMap<>();
    public void addPrototype(String key, Prototype prototype) {
        prototypes.put([1], [2]);
    }
    public Prototype getClone(String key) {
        return prototypes.get(key).clone();
    }
}
Drag options to blanks, or click blank then click option'
Akey
Bprototype
Cvalue
Dclone
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping key and prototype in the put method.
Using undefined variables.
5fill in blank
hard

Fill all three blanks to clone a prototype and modify its state.

LLD
Prototype original = registry.getClone([1]);
ConcretePrototype copy = (ConcretePrototype) original;
copy.[2] = [3];
Drag options to blanks, or click blank then click option'
A"item1"
Bid
C42
Dclone
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect key strings.
Trying to call clone again instead of modifying the field.
Assigning a string to an integer field.