-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathautomatic_door.py
63 lines (45 loc) · 1.11 KB
/
automatic_door.py
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
53
54
55
56
57
58
59
60
61
62
63
"""automactic door system using state pattern
"""
from abc import ABC, abstractmethod
class State(ABC):
"""State Abstract Class
"""
@abstractmethod
def action(self):
"""change state with do any action
"""
class OpenState(State):
"""Open State
"""
def action(self):
print("The door opened.")
class CloseState(State):
"""Close State
"""
def action(self):
print("The door closed.")
class DoorManagement(State):
"""Automatic door management."""
def __init__(self):
self.state: State = None
def get_state(self):
"""get door state
"""
return self.state
def set_state(self, state: State):
"""set door state
Args:
state (State): state of door
"""
self.state = state
def action(self):
self.state.action()
if __name__ == "__main__":
context = DoorManagement()
open_state = OpenState()
close_state = CloseState()
context.set_state(open_state)
context.action()
context.set_state(close_state)
context.action()
context.action()