-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreal.py
More file actions
40 lines (26 loc) · 684 Bytes
/
real.py
File metadata and controls
40 lines (26 loc) · 684 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
30
31
32
33
34
35
36
37
38
39
40
from abc import abstractmethod, ABCMeta
class State(metaclass=ABCMeta):
@abstractmethod
def doThis(self):
pass
class StartState(State):
def doThis(self):
print("TV Switching ON.")
class StopState(State):
def doThis(self):
print("TV Switching OFF.")
class TVContext(State):
def __init__(self):
self.state = None
def getState(self):
return self.state
def setState(self, state):
self.state = state
def doThis(self):
self.state.doThis()
if __name__ == "__main__":
context = TVContext()
start = StartState()
stop = StopState()
context.setState(stop)
context.doThis()