Bird
0
0
LLDsystem_design~10 mins

Command 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 define the Command interface method.

LLD
interface Command {
    void [1]();
}
Drag options to blanks, or click blank then click option'
Aexecute
Brun
Cstart
Dcall
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names like run or start which are not standard in Command pattern.
Leaving the method name empty or incorrect.
2fill in blank
medium

Complete the code to implement the execute method in a concrete command.

LLD
class LightOnCommand implements Command {
    private Light light;

    public LightOnCommand(Light light) {
        this.light = light;
    }

    public void [1]() {
        light.on();
    }
}
Drag options to blanks, or click blank then click option'
Aexecute
Bcall
Cstart
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name different from the interface.
Not calling the receiver's method inside execute.
3fill in blank
hard

Fix the error in the Invoker class to call the command properly.

LLD
class RemoteControl {
    private Command slot;

    public void setCommand(Command command) {
        this.slot = command;
    }

    public void buttonWasPressed() {
        slot.[1]();
    }
}
Drag options to blanks, or click blank then click option'
Acall
Brun
Cstart
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a method name not defined in the Command interface.
Forgetting to call the method on the command object.
4fill in blank
hard

Fill both blanks to complete the UndoableCommand interface extending Command and adding undo method.

LLD
interface UndoableCommand extends Command {
    void [1]();
    void [2]();
}
Drag options to blanks, or click blank then click option'
Aexecute
Bundo
Credo
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like redo or run.
Not including execute method in the interface.
5fill in blank
hard

Fill all three blanks to complete the Client code that creates a command, sets it to the invoker, and triggers execution.

LLD
Light light = new Light();
Command lightOn = new LightOnCommand([1]);
RemoteControl remote = new RemoteControl();
remote.[2](lightOn);
remote.[3]();
Drag options to blanks, or click blank then click option'
Alight
BsetCommand
CbuttonWasPressed
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Passing wrong object to command constructor.
Using wrong method names on the invoker.
Calling execute directly on the invoker.