Skip to content

Commit 89c5dc7

Browse files
committed
update AbstractFactory
1 parent 0142198 commit 89c5dc7

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

CreationalPatterns/AbstractFactory/README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ The Abstract Factory Pattern provides an interface for creating families of rela
1414
* Encapsulate object creation in a separate (factory) object. That is, define an interface (AbstractFactory) for creating objects, and implement the interface.
1515
* A class delegates object creation to a factory object instead of creating objects directly.
1616

17-
## Benefits
18-
19-
* Follows the Open/Close Principle.
20-
* Allows building families of product objects and guarantees their compatibility.
21-
* Avoids tight coupling between concrete products and code that uses them.
22-
* Divides responsibilities between multiple classes.
23-
24-
## Drawbacks
25-
26-
* Increases overall code complexity by creating multiple additional classes.
27-
2817
## Common Structure
2918

3019
![Common structure of abstract factoring pattern](https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Abstract_factory_UML.svg/677px-Abstract_factory_UML.svg.png)
@@ -39,7 +28,25 @@ The Abstract Factory Pattern provides an interface for creating families of rela
3928
* defines a product object to be created by the corresponding concrete factory
4029
* implements the AbstractProduct interface
4130

42-
_[Source: http://www.dofactory.com/net/abstract-factory-design-pattern]_
31+
## Collaboration
32+
33+
TODO - Add sequence diagram
34+
35+
* Normally a single instance of a ConcreteFactory class is created at runtime.
36+
37+
## Benefits
38+
39+
* Avoids tight coupling between concrete products and code that uses them.
40+
* Allows building families of product objects and guarantees their compatibility and consistency.
41+
* Divides responsibilities between multiple classes.
42+
43+
## Drawbacks
44+
45+
* Increases overall code complexity by creating multiple additional classes.
46+
* Supporting new kinds of products is difficult.
47+
* It requires extending the AbstractFactory interface, which involves changing all of its subclasses.
48+
49+
## Example
4350

4451
**Definition** - AbstractFactory and ConcreteFactory
4552
```cs
@@ -113,3 +120,9 @@ _[Source: http://www.dofactory.com/net/abstract-factory-design-pattern]_
113120
}
114121
}
115122
```
123+
124+
## Relations with Other Patterns
125+
126+
* **Factory Method** - AbstractFactory classes are often implemented with factory methods, but they can also be implemented using **Prototype**.
127+
128+
* **Singleton** - A concrete factory is often a singleton.

CreationalPatterns/FactoryMethod/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The Factory Method Pattern defines an interface for creating an object, but lets
99

1010
## Solution
1111

12-
* Define a separate operation `factory method` in the Creator/Factory class (e.g. AmericanPizzaFactory)
12+
* Define a separate operation `factory method` in the Creator class (e.g. CreatePizza() method in the AmericanPizzaStore class)
1313
* Move the constructor call (`new AmericanCheesePizza()`) inside the factory method.
1414

1515
**Definition**

0 commit comments

Comments
 (0)