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
@@ -120,3 +121,118 @@ public class MainTestFactory {
120
121
121
122
122
123
```
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
+
-**Use cases:**
127
+
- when class cannot anticipate the class of objects it must create.
128
+
- When class wants its subclasses to specify the objects it creates.
129
+
- when designing frameworks or libraries to give the best flexibility and isolation from concrete class types
130
+
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.
0 commit comments