Skip to content

Commit aafcdca

Browse files
committed
feature: Complete the pizza 🍕
1 parent 71a9ee3 commit aafcdca

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

chapter04_factory/pizza_abstract_factory.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def __str__(self):
1111
return "Shredded Mozzarella"
1212

1313

14+
class ParmesanCheese(Cheese):
15+
def __str__(self):
16+
return "Shredded Parmesan"
17+
18+
1419
class ReggianoCheese(Cheese):
1520
def __str__(self):
1621
return "Reggiano Cheese"
@@ -112,22 +117,22 @@ def __str__(self) -> str:
112117

113118

114119
class PizzaIngredientFactory(abc.ABC):
115-
def create_dough():
120+
def create_dough(self):
116121
raise NotImplementedError
117122

118-
def create_sauce():
123+
def create_sauce(self):
119124
raise NotImplementedError
120125

121-
def create_cheese():
126+
def create_cheese(self):
122127
raise NotImplementedError
123128

124-
def create_veggies():
129+
def create_veggies(self):
125130
raise NotImplementedError
126131

127-
def create_pepperoni():
132+
def create_pepperoni(self):
128133
raise NotImplementedError
129134

130-
def create_clam():
135+
def create_clam(self):
131136
raise NotImplementedError
132137

133138

@@ -264,8 +269,8 @@ class PizzaStore:
264269
def create_pizza(self, item):
265270
raise NotImplementedError
266271

267-
def order_pizza(self, type):
268-
pizza = self.create_pizza(type)
272+
def order_pizza(self, type_):
273+
pizza = self.create_pizza(type_)
269274
print(f"--- Making a {pizza.name} ---")
270275
pizza.prepare()
271276
pizza.bake()

chapter04_factory/readme.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22

33
> **Simple Factory**: A class which chooses which product class to instantiate and return, based upon method parameters.
44
5-
The Python standard library contains multiple references to factory objects, for instances in [dataclasses](https://docs.python.org/3/library/dataclasses.html?highlight=factory)
5+
The Python standard library contains multiple references to factory objects, for instances
6+
in [dataclasses](https://docs.python.org/3/library/dataclasses.html?highlight=factory).
7+
The Factory Boy package provides easy object creation for Django
8+
and for other ORMs.
69

7-
> **Factory Method**: Defines an interface for creating an object, but lets subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses.
10+
> **Factory Method**: Defines an interface for creating an object, but lets subclasses decide which class to
11+
> instantiate. The Factory method lets a class defer instantiation to subclasses.
812
9-
For instance the `PizzaStore` abstract class in this repo provides an abstract `create_pizza` interface for creating one product.
13+
For instance the `PizzaStore` abstract class in this repo provides an abstract `create_pizza` interface for creating one
14+
product.
1015

11-
The [python-qrcode](https://github.com/dancergraham/python-qrcode) module uses the factory method pattern nicely to separate only the part of the code that changes (generating png, svg, etc) from the underlying logic of the code generation and to allow extension through the creation of new factory methods without modification of the existing code. I took advantage of this to add a new class for the creation of 3D QR codes with my favourite NURBS modelling software Rhino.
16+
The [python-qrcode](https://github.com/dancergraham/python-qrcode) module uses the factory method pattern nicely to
17+
separate only the part of the code that changes (generating png, svg, etc.) from the underlying logic of the code
18+
generation and to allow extension through the creation of new factory methods without modification of the existing code.
19+
I took advantage of this to add a new class for the creation of 3D QR codes with my favourite NURBS modelling software
20+
Rhino.
1221

13-
> **Abstract Factory**: Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
22+
> **Abstract Factory**: Provides an interface for creating families of related or dependent objects without specifying
23+
> their concrete classes.
1424
1525
For instance the `PizzaIngredientFactory` abstract class defines an interface for a family of products.

0 commit comments

Comments
 (0)