Skip to content

Commit 7b2f4c8

Browse files
committed
Command pattern remote : start implementation
1 parent c275a96 commit 7b2f4c8

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

chapter06_command/remote_undo.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import abc
2+
3+
4+
class Command(abc.ABC):
5+
def execute(self):
6+
raise NotImplementedError
7+
8+
def undo(self):
9+
raise NotImplementedError
10+
11+
12+
class NoCommand(Command):
13+
def execute(self):
14+
pass
15+
16+
def undo(self):
17+
pass
18+
19+
20+
class LightOnCommand(Command):
21+
def __init__(self, light):
22+
self.light = light
23+
24+
def execute(self):
25+
self.level = self.light.getLevel()
26+
self.light.on()
27+
28+
def undo(self):
29+
self.light.dim(self.level)
30+
31+
32+
class LightOffCommand(Command):
33+
def __init__(self, light):
34+
self.light = light
35+
36+
def execute(self):
37+
self.level = self.light.getLevel()
38+
self.light.off()
39+
40+
def undo(self):
41+
self.light.dim(self.level)

0 commit comments

Comments
 (0)