|
2 | 2 |
|
3 | 3 | > **Simple Factory**: A class which chooses which product class to instantiate and return, based upon method parameters.
|
4 | 4 |
|
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. |
6 | 9 |
|
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. |
8 | 12 |
|
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. |
10 | 15 |
|
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. |
12 | 21 |
|
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. |
14 | 24 |
|
15 | 25 | For instance the `PizzaIngredientFactory` abstract class defines an interface for a family of products.
|
| 26 | + |
| 27 | +## Running the code |
| 28 | + |
| 29 | +```bash |
| 30 | +python pizza_abstract_factory.py |
| 31 | +``` |
0 commit comments