Skip to content

Commit 6a431d9

Browse files
committed
docs: improve formatting and clarity in Factory Method pattern documentation
1 parent b1a85fc commit 6a431d9

File tree

1 file changed

+23
-13
lines changed
  • creational_design_pattern/factory_method

1 file changed

+23
-13
lines changed

creational_design_pattern/factory_method/README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
11
# Factory Method Pattern
2+
23
Also known as: `Virtual Constructor`
34

45
- is a creational pattern.
56
- 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.
67

78
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.
89

9-
10-
1110
## Sections
1211

1312
- [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)
1716
- [Resources](#Resources)
1817

1918
## Examples
2019

2120
### shape Example
21+
2222
source: [Tutorial Point java ](https://www.tutorialspoint.com/design_pattern/factory_pattern.htm)
2323
<img src="assets/factory_pattern_uml_diagram.jpg" >
2424

25-
2625
#### Step 1
27-
Create an interface.
26+
27+
Create an interface.
2828

2929
```dart
3030
abstract class IShape {
3131
const IShape();
3232
void draw();
3333
}
3434
```
35+
3536
#### Step 2
36-
Create concrete classes implementing the same interface.
37+
38+
Create concrete classes implementing the same interface.
39+
3740
```dart
3841
class Rectangle implements IShape {
3942
@override
@@ -50,8 +53,11 @@ class Circle implements IShape {
5053
void draw() => print("Inside Circle::draw() method.");
5154
}
5255
```
56+
5357
#### Step 3
54-
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+
5561
```dart
5662
enum ShapeType { CIRCLE, RECTANGLE, SQUARE }
5763
@@ -73,6 +79,7 @@ class ShapeFactory {
7379
```
7480

7581
#### Step 4
82+
7683
Use the Factory to get object of concrete class by passing an information such as type.
7784

7885
```dart
@@ -94,14 +101,17 @@ void main() {
94101
```
95102

96103
---
104+
97105
### Dialog Example
106+
98107
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.
99108

100109
- <strong><a href="dialog_example" target="_blank"> Dialog Example</a></strong>
101110

102-
103111
---
112+
104113
### vessel volume Example
114+
105115
source: [Design Pattern in Dart ( factory method ) ](https://github.com/scottt2/design-patterns-in-dart/tree/master/factor_method)
106116

107117
`updated code in coffee_example.dart`
@@ -164,8 +174,8 @@ void main() {
164174
}
165175
```
166176

177+
## Resources
167178

168-
## Resources
169-
- [Wikipedia: Factory Method](https://en.wikipedia.org/wiki/Factory_method_pattern)
179+
- [Wikipedia: Factory Method](https://en.wikipedia.org/wiki/Factory_method_pattern)
170180

171-
- [Design Pattern in Dart ( factory method ) ](https://github.com/scottt2/design-patterns-in-dart/tree/master/factor_method)
181+
- [Design Pattern in Dart (factory method) ](https://github.com/scottt2/design-patterns-in-dart/tree/master/factor_method)

0 commit comments

Comments
 (0)