forked from Devansh-Maurya/Design-Patterns-And-Principles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemoteLoader.kt
52 lines (39 loc) · 1.4 KB
/
RemoteLoader.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
41
42
43
44
45
46
47
48
49
50
51
52
package command
import command.command.*
import command.invoker.RemoteControl
import command.receiver.Light
import command.receiver.Stereo
/**
* Created by devansh on 12/09/20.
*/
fun main() {
val remoteControl = RemoteControl()
val livingRoomLight = Light("Living Room")
val kitchenLight = Light("Kitchen")
val stereo = Stereo("Living Room")
val livingRoomLightOn = LightOnCommand(livingRoomLight)
val livingRoomLightOff = LightOffCommand(livingRoomLight)
val kitchenLightOn = LightOnCommand(kitchenLight)
val kitchenLightOff = LightOffCommand(kitchenLight)
val stereoOnWithCD = StereoOnWithCDCommand(stereo)
val stereoOff = StereoOffCommand(stereo)
val partyOnMacro = MacroCommand(listOf(livingRoomLightOn, stereoOnWithCD))
val partyOffMacro = MacroCommand(listOf(livingRoomLightOff, stereoOff))
remoteControl.run {
setCommand(0, livingRoomLightOn, livingRoomLightOff)
setCommand(1, kitchenLightOn, kitchenLightOff)
setCommand(2, stereoOnWithCD, stereoOff)
setCommand(3, partyOnMacro, partyOffMacro)
println(this)
onButtonPushed(0)
offButtonPushed(0)
onButtonPushed(1)
offButtonPushed(1)
onButtonPushed(2)
offButtonPushed(2)
println("--- Pushing Macro On ---")
onButtonPushed(3)
println("--- Pushing Macro Off ---")
offButtonPushed(3)
}
}