@@ -37,7 +37,7 @@ def __str__(self):
37
37
38
38
39
39
class FreshClams (Clams ):
40
- def __str__self ( ):
40
+ def __str__ ( self ):
41
41
return "Fresh Clams from Long Island Sound"
42
42
43
43
@@ -114,68 +114,84 @@ def __str__(self) -> str:
114
114
class PizzaIngredientFactory (abc .ABC ):
115
115
def create_dough ():
116
116
raise NotImplementedError
117
+
117
118
def create_sauce ():
118
119
raise NotImplementedError
120
+
119
121
def create_cheese ():
120
122
raise NotImplementedError
123
+
121
124
def create_veggies ():
122
125
raise NotImplementedError
126
+
123
127
def create_pepperoni ():
124
128
raise NotImplementedError
129
+
125
130
def create_clam ():
126
131
raise NotImplementedError
127
132
128
133
129
134
class ChicagoPizzaIngredientFactory (PizzaIngredientFactory ):
130
- def create_dough ():
135
+ def create_dough (self ):
131
136
return ThickCrustDough ()
132
- def create_sauce ():
137
+
138
+ def create_sauce (self ):
133
139
return PlumTomatoSauce ()
134
- def create_cheese ():
140
+
141
+ def create_cheese (self ):
135
142
return MozzarellaCheese ()
136
- def create_veggies ():
137
- return [BlackOlives (), Spinach (), Eggplant ()]
138
- def create_pepperoni ():
143
+
144
+ def create_veggies (self ):
145
+ return [BlackOlives (), Spinach (), Eggplant ()]
146
+
147
+ def create_pepperoni (self ):
139
148
return SlicedPepperoni ()
140
- def create_clam ():
149
+
150
+ def create_clam (self ):
141
151
return FrozenClams ()
142
152
143
153
144
154
class NYPizzaIngredientFactory (PizzaIngredientFactory ):
145
- def create_dough ():
155
+ def create_dough (self ):
146
156
return ThinCrustDough ()
147
- def create_sauce ():
157
+
158
+ def create_sauce (self ):
148
159
return MarinaraSauce ()
149
- def create_cheese ():
160
+
161
+ def create_cheese (self ):
150
162
return ReggianoCheese ()
151
- def create_veggies ():
152
- return [Garlic (), Onion (), Mushroom (), RedPepper ()]
153
- def create_pepperoni ():
163
+
164
+ def create_veggies (self ):
165
+ return [Garlic (), Onion (), Mushroom (), RedPepper ()]
166
+
167
+ def create_pepperoni (self ):
154
168
return SlicedPepperoni ()
155
- def create_clam ():
169
+
170
+ def create_clam (self ):
156
171
return FreshClams ()
157
172
158
173
159
174
class Pizza :
160
- def __init__ (self ):
175
+ def __init__ (self , ingredient_factory ):
176
+ self .ingredient_factory = ingredient_factory
161
177
self .name = None
162
178
self .dough = None
163
179
self .sauce = None
164
180
self .cheese = None
165
181
self .veggies = []
166
182
self .pepperoni = None
167
- self .clams = None
168
-
169
- def prepare ():
183
+ self .clam = None
184
+
185
+ def prepare (self ):
170
186
raise NotImplementedError
171
187
172
- def bake ():
188
+ def bake (self ):
173
189
print ("Bake for 25 minutes at 350" )
174
190
175
- def cut ():
191
+ def cut (self ):
176
192
print ("Cutting the pizza into diagonal slices" )
177
193
178
- def box ():
194
+ def box (self ):
179
195
print ("Place pizza in official PizzaStore box" )
180
196
181
197
def set_name (self , name ):
@@ -186,32 +202,62 @@ def get_name(self):
186
202
187
203
def __str__ (self ):
188
204
result = []
189
- result .append ("---- " + name + " ----\n " )
205
+ result .append ("---- " + self . name + " ----" )
190
206
if self .dough :
191
207
result .append (self .dough )
192
- result .append ("\n " )
193
-
208
+
194
209
if self .sauce :
195
210
result .append (self .sauce )
196
- result .append ("\n " )
197
-
211
+
198
212
if self .cheese :
199
213
result .append (self .cheese )
200
- result .append ("\n " )
201
-
214
+
202
215
if self .veggies :
203
- result .append (", " .join (self .veggies ))
204
- result .append ("\n " )
205
-
216
+ result .append (", " .join (map (str ,self .veggies )))
217
+
206
218
if self .clam :
207
219
result .append (self .clam )
208
- result .append ("\n " )
209
-
220
+
210
221
if self .pepperoni :
211
222
result .append (self .pepperoni )
212
- result .append ("\n " )
213
223
214
- return "" .join (result )
224
+ return "\n " .join (map (str , result ))+ "\n "
225
+
226
+
227
+ class CheesePizza (Pizza ):
228
+ def prepare (self ):
229
+ print (f"Preparing { self .name } " )
230
+ self .dough = self .ingredient_factory .create_dough ()
231
+ self .sauce = self .ingredient_factory .create_sauce ()
232
+ self .cheese = self .ingredient_factory .create_cheese ()
233
+
234
+
235
+ class ClamPizza (Pizza ):
236
+ def prepare (self ):
237
+ print (f"Preparing { self .name } " )
238
+ self .dough = self .ingredient_factory .create_dough ()
239
+ self .sauce = self .ingredient_factory .create_sauce ()
240
+ self .cheese = self .ingredient_factory .create_cheese ()
241
+ self .clam = self .ingredient_factory .create_clam ()
242
+
243
+
244
+ class VeggiePizza (Pizza ):
245
+ def prepare (self ):
246
+ print (f"Preparing { self .name } " )
247
+ self .dough = self .ingredient_factory .create_dough ()
248
+ self .sauce = self .ingredient_factory .create_sauce ()
249
+ self .cheese = self .ingredient_factory .create_cheese ()
250
+ self .veggies = self .ingredient_factory .create_veggies ()
251
+
252
+
253
+ class PepperoniPizza (Pizza ):
254
+ def prepare (self ):
255
+ print (f"Preparing { self .name } " )
256
+ self .dough = self .ingredient_factory .create_dough ()
257
+ self .sauce = self .ingredient_factory .create_sauce ()
258
+ self .cheese = self .ingredient_factory .create_cheese ()
259
+ self .veggies = self .ingredient_factory .create_veggies ()
260
+ self .pepperoni = self .ingredient_factory .create_pepperoni ()
215
261
216
262
217
263
class PizzaStore :
@@ -220,7 +266,7 @@ def create_pizza(self, item):
220
266
221
267
def order_pizza (self , type ):
222
268
pizza = self .create_pizza (type )
223
- print (f"--- Making a { pizza .get_name () } ---" )
269
+ print (f"--- Making a { pizza .name } ---" )
224
270
pizza .prepare ()
225
271
pizza .bake ()
226
272
pizza .cut ()
@@ -232,5 +278,64 @@ class ChicagoPizzaStore(PizzaStore):
232
278
def create_pizza (self , item ):
233
279
pizza = None
234
280
ingredient_factory = ChicagoPizzaIngredientFactory ()
235
- if item == 'cheese' :
236
- pizza = new Chee
281
+ if item == "cheese" :
282
+ pizza = CheesePizza (ingredient_factory )
283
+ pizza .name = "Chicago Style Cheese Pizza"
284
+ elif item == "veggie" :
285
+ pizza = VeggiePizza (ingredient_factory )
286
+ pizza .name = "Chicago Style Veggie Pizza"
287
+ elif item == "clam" :
288
+ pizza = ClamPizza (ingredient_factory )
289
+ pizza .name = "Chicago Style Clam Pizza"
290
+ elif item == "pepperoni" :
291
+ pizza = PepperoniPizza (ingredient_factory )
292
+ pizza .name = "Chicago Style Pepperoni Pizza"
293
+ return pizza
294
+
295
+
296
+ class NYPizzaStore (PizzaStore ):
297
+ def create_pizza (self , item ):
298
+ pizza = None
299
+ ingredient_factory = NYPizzaIngredientFactory ()
300
+ if item == "cheese" :
301
+ pizza = CheesePizza (ingredient_factory )
302
+ pizza .name = "New York Style Cheese Pizza"
303
+ elif item == "veggie" :
304
+ pizza = VeggiePizza (ingredient_factory )
305
+ pizza .name = "New York Style Veggie Pizza"
306
+ elif item == "clam" :
307
+ pizza = ClamPizza (ingredient_factory )
308
+ pizza .name = "New York Style Clam Pizza"
309
+ elif item == "pepperoni" :
310
+ pizza = PepperoniPizza (ingredient_factory )
311
+ pizza .name = "New York Style Pepperoni Pizza"
312
+ return pizza
313
+
314
+
315
+ def pizza_test_drive ():
316
+ ny_store = NYPizzaStore ()
317
+ chicago_store = ChicagoPizzaStore ()
318
+
319
+ pizza = ny_store .order_pizza ("cheese" )
320
+ print (f"Joel ordered a { pizza } " )
321
+ pizza = chicago_store .order_pizza ("cheese" )
322
+ print (f"Joel ordered a { pizza } " )
323
+
324
+ pizza = ny_store .order_pizza ("clam" )
325
+ print (f"Joel ordered a { pizza } " )
326
+ pizza = chicago_store .order_pizza ("clam" )
327
+ print (f"Joel ordered a { pizza } " )
328
+
329
+ pizza = ny_store .order_pizza ("pepperoni" )
330
+ print (f"Joel ordered a { pizza } " )
331
+ pizza = chicago_store .order_pizza ("pepperoni" )
332
+ print (f"Joel ordered a { pizza } " )
333
+
334
+ pizza = ny_store .order_pizza ("veggie" )
335
+ print (f"Joel ordered a { pizza } " )
336
+ pizza = chicago_store .order_pizza ("veggie" )
337
+ print (f"Joel ordered a { pizza } " )
338
+
339
+
340
+ if __name__ == "__main__" :
341
+ pizza_test_drive ()
0 commit comments