You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: factory-kit/README.md
+27-26Lines changed: 27 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@ title: Factory Kit
3
3
category: Creational
4
4
language: en
5
5
tag:
6
+
- Abstraction
6
7
- Decoupling
7
8
- Encapsulation
8
9
- Generic
@@ -23,14 +24,16 @@ Define a factory of immutable content with separated builder and factory interfa
23
24
24
25
Real-world example
25
26
26
-
> Imagine a magical weapon factory that can create any type of weapon wished for. When the factory is unboxed, the master recites the weapon types needed to prepare it. After that, any of those weapon types can be summoned in an instant.
27
+
> An analogous real-world example of the Factory Kit pattern is a restaurant kitchen where different types of dishes are prepared. Imagine the kitchen has a central station with various ingredients and recipes registered for different dishes. When an order comes in, the chef consults this central station to gather the necessary ingredients and follow the registered recipe to prepare the dish. This setup allows the kitchen to efficiently manage and switch between different dish preparations without the need for each chef to know the specifics of every recipe, promoting flexibility and consistency in the cooking process.
27
28
28
29
In plain words
29
30
30
31
> Factory kit is a configurable object builder, a factory to create factories.
31
32
32
33
**Programmatic Example**
33
34
35
+
Imagine a magical weapon factory capable of creating any desired weapon. Upon activation, the master recites the names of the weapon types needed to configure it. Once set up, any of these weapon types can be summoned instantly.
36
+
34
37
Let's first define the simple `Weapon` hierarchy.
35
38
36
39
```java
@@ -80,33 +83,31 @@ public interface WeaponFactory {
* In Java libraries such as the Java Development Kit (JDK) where different rendering engines might be instantiated based on the runtime environment.
@@ -140,10 +145,6 @@ Trade-offs:
140
145
* [Builder](https://java-design-patterns.com/patterns/builder/): Can be used to construct complex objects step-by-step using a similar approach.
141
146
* [Prototype](https://java-design-patterns.com/patterns/prototype/): Objects that are created by cloning a prototypical instance often use a factory to manage it.
0 commit comments