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
- when the class does not know beforehand the exact types and dependencies of the objects it needs to create.
23
25
- When a method returns one of several possible classes that share a common super class and wants to encapsulate the logic of which object to create.
24
26
- when designing frameworks or libraries to give the best flexibility and isolation from concrete class types
25
27
26
-
-**Examples:** You want to manufacture the products. You must be able to create both A and B (C,D) products and switch between them without modify the existing source codes.
28
+
-**Examples:** You want to manufacture the products many times.
27
29
- Design UML:
28
30

29
31
@@ -121,14 +123,16 @@ public class MainTestFactory {
121
123
122
124
123
125
```
124
-
## 2. 🏭 Factory Method
125
-
- Factory method provides a way to delegate the instantiation logic to child classes.Defines an interface for creating objects, but let subclasses to decide which class to instantiate. Refers to the newly created object through a common interface
126
+
<br>
127
+
128
+
## 1.2. 🏭 Factory Method
129
+
-**Factory Method** is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.
126
130
-**Use cases:**
127
131
- when class cannot anticipate the class of objects it must create.
128
-
- When class wants its subclasses to specify the objects it creates.
132
+
- When class **wants its subclasses** to **specify the objects it creates**.
129
133
- when designing frameworks or libraries to give the best flexibility and isolation from concrete class types
130
134
131
-
-**Examples:** You want to manufacture the products. You must be able to create both A and B (C,D) products and switch between them without modify the existing source codes.
135
+
-**Examples:** You want to manufacture the products. You must be able to create both A and B (C,D) products and add/switch between them without modify the existing source codes.
132
136
- Design UML:
133
137

134
138
@@ -233,4 +237,159 @@ public class MainTestFactory {
233
237
234
238
}
235
239
240
+
```
241
+
242
+
<br>
243
+
244
+
## 1.3. 🔨 Abstract Factory
245
+
-**Abstract Factory** is a creational design pattern that lets you produce families of related objects without specifying their concrete classes.
246
+
-**Use cases:**
247
+
- when need a way to **create individual furniture objects** so that they **match other objects of the same family**.
248
+
- When don’t want to change existing code when adding new products or families of products to the program.
249
+
250
+
-**Examples:** You intend to manufacture a product line that included a family of related products: A,B,and C - along with several variants such as AWin,ALinux, BWin,BLinux, CWin, and CLinux.
0 commit comments