-
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathclient.py
More file actions
29 lines (23 loc) · 703 Bytes
/
client.py
File metadata and controls
29 lines (23 loc) · 703 Bytes
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
"The Command Pattern Use Case Example. A smart light Switch"
from light import Light
from switch import Switch
from switch_on_command import SwitchOnCommand
from switch_off_command import SwitchOffCommand
# Create a receiver
LIGHT = Light()
# Create Commands
SWITCH_ON = SwitchOnCommand(LIGHT)
SWITCH_OFF = SwitchOffCommand(LIGHT)
# Register the commands with the invoker
SWITCH = Switch()
SWITCH.register("ON", SWITCH_ON)
SWITCH.register("OFF", SWITCH_OFF)
# Execute the commands that are registered on the Invoker
SWITCH.execute("ON")
SWITCH.execute("OFF")
SWITCH.execute("ON")
SWITCH.execute("OFF")
# show history
SWITCH.show_history()
# replay last two executed commands
SWITCH.replay_last(2)