-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.py
More file actions
executable file
·48 lines (30 loc) · 751 Bytes
/
Copy pathstate.py
File metadata and controls
executable file
·48 lines (30 loc) · 751 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
41
42
43
44
45
46
47
48
class AtmState():
name = "state"
allowed = []
def goNext(self, state):
if state.name in self.allowed:
print("Current State: ", self, " switched to: ", state.name)
self.__class__ = state
else:
print("Current State: ", self, " switching to: ", state.name, " not possible!")
def __str__(self):
return self.name
class Off(AtmState):
name = "off"
allowed = ['on']
class On(AtmState):
name = "on"
allowed = ['off']
class ATM():
def __init__(self):
self.current = Off()
def setState(self, state):
self.current.goNext(state)
def main():
atm = ATM()
atm.setState(On)
atm.setState(Off)
atm.setState(On)
atm.setState(On)
if __name__ == "__main__":
main()