forked from dancergraham/HeadFirstDesignPatterns_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coffee.py
67 lines (43 loc) · 1.34 KB
/
coffee.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
64
65
66
67
import abc
# TODO : Add Dark roast, Soy, Whip
class Beverage(abc.ABC):
"""Base class for all beverages"""
def __init__(self):
self.description = "Unknown Beverage"
def get_description(self):
return self.description
@abc.abstractmethod
def cost(self):
raise NotImplementedError
class CondimentDecorator(Beverage, abc.ABC):
"""Base class for all condiments"""
@abc.abstractmethod
def get_description(self):
raise NotImplementedError
class Espresso(Beverage):
def __init__(self):
self.description = "Espresso"
def cost(self):
return 1.99
class HouseBlend(Beverage):
def __init__(self):
self.description = "House Blend Coffee"
def cost(self):
return 0.89
class Mocha(CondimentDecorator):
def __init__(self, beverage: Beverage):
self.beverage = beverage
def get_description(self):
return self.beverage.get_description() + ", Mocha"
def cost(self):
return self.beverage.cost() + 0.20
def star_buzz_coffee():
"""Test code"""
beverage = Espresso()
print(beverage.get_description(), beverage.cost())
beverage3 = HouseBlend()
beverage3 = Mocha(beverage3)
beverage3 = Mocha(beverage3)
print(beverage3.get_description(), beverage3.cost())
if __name__ == "__main__":
star_buzz_coffee()