@@ -137,7 +137,7 @@ _Design of the Remote Control_
137137
138138First, create the ` Command.java ` interface. This defines what every Command must do:
139139
140- ``` java
140+ ``` java title="Command.java"
141141interface Command {
142142 public void execute ();
143143 public void undo ();
@@ -146,7 +146,7 @@ interface Command {
146146
147147Next, make the Receiver classes. A Receiver carries out the real work.
148148
149- ``` java
149+ ``` java title="Light.java"
150150class Light {
151151 public void off () {
152152 System . out. println(" Light is Turned Off" );
@@ -158,7 +158,7 @@ class Light {
158158}
159159```
160160
161- ``` java
161+ ``` java title="LivingRoom.java"
162162class LivingRoom {
163163 public void off () {
164164 System . out. println(" Living Room Light is turned off" );
@@ -178,7 +178,7 @@ class LivingRoom {
178178}
179179```
180180
181- ``` java
181+ ``` java title="CeilingFan.java"
182182class CeilingFan {
183183 public static final int OFF = 0 ;
184184 public static final int HIGH = 3 ;
@@ -214,7 +214,7 @@ class CeilingFan {
214214
215215Now write the concrete Command classes. Each one wraps a Receiver and calls its methods.
216216
217- ``` java
217+ ``` java title"LightOnCommand.java"
218218class LightOnCommand implements Command {
219219 private Light light;
220220
@@ -239,7 +239,7 @@ class LightOnCommand implements Command {
239239}
240240```
241241
242- ``` java
242+ ``` java title="LightOffCommand.java"
243243class LightOffCommand implements Command {
244244 private Light light;
245245
@@ -264,7 +264,7 @@ class LightOffCommand implements Command {
264264}
265265```
266266
267- ``` java
267+ ``` java title="LivingRoomOnCommand.java"
268268class LivingRoomOnCommand implements Command {
269269 private LivingRoom livingroom;
270270
@@ -291,7 +291,7 @@ class LivingRoomOnCommand implements Command {
291291}
292292```
293293
294- ``` java
294+ ``` java title="LivingRoomOffCommand.java"
295295class LivingRoomOffCommand implements Command {
296296 private LivingRoom livingroom;
297297
@@ -322,7 +322,7 @@ You would follow the same pattern for the CeilingFan commands.
322322
323323Finally, put everything together in the Invoker:
324324
325- ``` java
325+ ``` java title="RemoteControl.java"
326326class RemoteControl {
327327 private Command [] onCommands;
328328 private Command [] offCommands;
0 commit comments