-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoffeesMachine.py
More file actions
101 lines (79 loc) · 2.2 KB
/
coffeesMachine.py
File metadata and controls
101 lines (79 loc) · 2.2 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import abc
__author__ = 'Bruno'
class MachineContext:
"""
Define's the machine's context
"""
def __init__(self):
"""
Constructor
"""
self.state = TurnOnState()
class State:
"""
Define's the abstract state
"""
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def handle(self, machine_context):
"""
Define's the abstract method for handle
:param machine_context: the context of the operation
:return:
"""
raise NotImplementedError
class BringCupState(State):
"""
Define's the State where a cup is bring
"""
def handle(self, machine_context):
"""
Bring a cup to the machine
:param machine_context: the context of the operation
"""
print("Bringing a cup")
machine_context.state = ApplyCoffeeState()
class ApplyCoffeeState(State):
"""
Define's the State where coffee is applied
"""
def handle(self, machine_context):
"""
Apply coffee to the cup
:param machine_context: the context of the operation
"""
print("Applying coffee to the cup")
machine_context.state = FillWaterState()
class FillWaterState(State):
"""
Define's the State where the cup is filled with water
"""
def handle(self, machine_context):
"""
Fill the cup with water
:param machine_context: the context of the operation
"""
print("Filling water")
machine_context.state = TurnOffState()
class TurnOffState(State):
"""
Define's the State where the machine is turned off
"""
def handle(self, machine_context):
"""
Turn off the machine
:param machine_context: the context of the operation
"""
print("Turned Off - Take your coffee")
machine_context.state = None
class TurnOnState(State):
"""
Define's the State where the machine is turned on
"""
def handle(self, machine_context):
"""
Turn on the machine
:param machine_context: the context of the operation
"""
print("Turned On- Please, wait")
machine_context.state = BringCupState()