-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathRemoteLoaderWithUndo.kt
40 lines (29 loc) · 953 Bytes
/
RemoteLoaderWithUndo.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package command
import command.command.LightOffCommand
import command.command.LightOnCommand
import command.invoker.RemoteControlWithUndo
import command.receiver.Light
/**
* Created by devansh on 12/09/20.
*/
fun main() {
val remoteControl = RemoteControlWithUndo()
val livingRoomLight = Light("Living Room")
val kitchenLight = Light("Kitchen")
val livingRoomLightOn = LightOnCommand(livingRoomLight)
val livingRoomLightOff = LightOffCommand(livingRoomLight)
val kitchenLightOn = LightOnCommand(kitchenLight)
val kitchenLightOff = LightOffCommand(kitchenLight)
remoteControl.run {
setCommand(0, livingRoomLightOn, livingRoomLightOff)
setCommand(1, kitchenLightOn, kitchenLightOff)
onButtonPushed(0)
offButtonPushed(0)
println(this)
undoButtonPushed()
onButtonPushed(1)
offButtonPushed(1)
println(this)
undoButtonPushed()
}
}