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 to
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 and 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 mainString args
RemoteContral control new RemoteControl ;
Light light new Light ;
Command lightsOn new LightsOnCommandlight;
Command lightsOff new LightsOffCommandlight;
GarageDoor garageDoor new GarageDoor ;
Command garageDoorOpen new GarageDoorOpenCommand garageDoor ;
Command garageDoorClose new GarageDoorCloseCommand garageDoor;
switch on
control.setcommand ightsOn;
control.pressButton;
switch off
control.setCommand lightsOff;
control.pressButton;
switch on
control.setcommand garageDoorOpen;
control.pressButton;
switch off
control.setcommand garageDoorClose;
control.pressButton;
l
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
