Question: Command Design Pattern The objective of this exercise is to implement the command design pattern. Answer Question 1 to 7 First, we'll create our command

Command Design Pattern
The objective of this exercise is to implement the command design pattern.
Answer Question 1 to 7
First, we'll create our command interface:
Now let's create two concrete commands. One will turn on the lights, another turns off lights:
Light is our receiver class, so let's set that up now:
Following the step 2 and 3, create commands for the GarageDoorOpenCommand and
GarageDoorCloseCommand, and the receiver GarageDoor
Our invoker in this case is the remote control.
set up a client to use the invoker
//Client
public class client}
public static void main(String[] args){
RemoteContral control = new RemoteControl ();
Light light = new Light ();
Command lightsOn = new LightsOnCommand(light);
Command lightsOff = new LightsOffCommand(light);
GarageDoor garageDoor = new GarageDoor ();
Command garageDoorOpen = new GarageDoorOpenCommand (garageDoor) ;
Command garageDoorClose = new GarageDoorCloseCommand (garageDoor);
//switch on
control.setcommand (1ightsOn);
control.pressButton();
//switch off
control.setCommand (lightsOff);
control.pressButton();
//switch on
control.setcommand (garageDoorOpen);
control.pressButton();
//switch off
control.setcommand (garageDoorClose);
control.pressButton();
}
l
Command Design Pattern The objective of this

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!