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: creational_design_pattern/factory_method/README.md
+23-13Lines changed: 23 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,39 +1,42 @@
1
1
# Factory Method Pattern
2
+
2
3
Also known as: `Virtual Constructor`
3
4
4
5
- is a creational pattern.
5
6
- uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created.
6
7
7
8
This is done by creating objects by calling a factory method—either specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived classes—rather than by calling a constructor.
8
9
9
-
10
-
11
10
## Sections
12
11
13
12
-[Examples](#Examples)
14
-
-[shape Example](#shape-Example)
15
-
-[Dialog Example](#Dialog-Example)
16
-
-[vessel volume Example](#vessel-volume-Example)
13
+
-[shape Example](#shape-Example)
14
+
-[Dialog Example](#Dialog-Example)
15
+
-[vessel volume Example](#vessel-volume-Example)
17
16
-[Resources](#Resources)
18
17
19
18
## Examples
20
19
21
20
### shape Example
21
+
22
22
source: [Tutorial Point java ](https://www.tutorialspoint.com/design_pattern/factory_pattern.htm)
Create a Factory to generate object of concrete class based on given information.
58
+
59
+
Create a Factory to generate object of concrete class based on given information.
60
+
55
61
```dart
56
62
enum ShapeType { CIRCLE, RECTANGLE, SQUARE }
57
63
@@ -73,6 +79,7 @@ class ShapeFactory {
73
79
```
74
80
75
81
#### Step 4
82
+
76
83
Use the Factory to get object of concrete class by passing an information such as type.
77
84
78
85
```dart
@@ -94,14 +101,17 @@ void main() {
94
101
```
95
102
96
103
---
104
+
97
105
### Dialog Example
106
+
98
107
This example illustrates how the Factory Method can be used for creating cross-platform UI elements without coupling the client code to concrete UI classes.
0 commit comments