-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathmain.py
81 lines (56 loc) · 1.71 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from abc import ABCMeta, abstractmethod
class PizzaFactory(metaclass=ABCMeta):
@abstractmethod
def create_veg_pizza(self):
pass
@abstractmethod
def create_non_veg_pizza(self):
pass
class IndianPizzaFactory(PizzaFactory):
def create_veg_pizza(self):
return DeluxeVeggiePizza()
def create_non_veg_pizza(self):
return ChickenPizza()
class USPizzaFactory(PizzaFactory):
def create_veg_pizza(self):
return MexicanVegPizza()
def create_non_veg_pizza(self):
return HamPizza()
class VegPizza(metaclass=ABCMeta):
@abstractmethod
def prepare(self, veg_pizza):
pass
class NonVegPizza(metaclass=ABCMeta):
@abstractmethod
def serve(self, veg_pizza):
pass
class DeluxeVeggiePizza(VegPizza):
def prepare(self):
print('Prepare', type(self).__name__)
class ChickenPizza(NonVegPizza):
def serve(self, veg_pizza):
print(
type(self).__name__,
'is served with Chicken on',
type(veg_pizza).__name__,
)
class MexicanVegPizza(VegPizza):
def prepare(self):
print('Prepare', type(self).__name__)
class HamPizza(NonVegPizza):
def serve(self, veg_pizza):
print(
type(self).__name__,
'is served with Ham on',
type(veg_pizza).__name__,
)
class PizzaStore:
def make_pizzas(self):
for factory in [IndianPizzaFactory(), USPizzaFactory()]:
non_veg_pizza = factory.create_non_veg_pizza()
veg_pizza = factory.create_veg_pizza()
veg_pizza.prepare()
non_veg_pizza.serve(veg_pizza)
if __name__ == '__main__':
pizza = PizzaStore()
pizza.make_pizzas()