3. Given the following code snippet implementing the Command pattern, what will be the output?
class Light {
turnOn() { console.log('Light is ON'); }
turnOff() { console.log('Light is OFF'); }
}
class TurnOnCommand {
constructor(light) { this.light = light; }
execute() { this.light.turnOn(); }
}
class TurnOffCommand {
constructor(light) { this.light = light; }
execute() { this.light.turnOff(); }
}
class RemoteControl {
setCommand(command) { this.command = command; }
pressButton() { this.command.execute(); }
}
const light = new Light();
const remote = new RemoteControl();
remote.setCommand(new TurnOnCommand(light));
remote.pressButton();
remote.setCommand(new TurnOffCommand(light));
remote.pressButton();