Skip to content

Commit 804f3bf

Browse files
committed
Add README to example.
1 parent c6030de commit 804f3bf

File tree

1 file changed

+39
-0
lines changed
  • patterns/factory_method/concaptual_platform_dialog

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Abstract Factory pattern
2+
Factory Method is a creational design pattern that provides an interface for creating objects in a
3+
superclass, but allows subclasses to alter the type of objects that will be created.
4+
5+
Tutorial: [here](https://refactoring.guru/design-patterns/factory-method).
6+
7+
### About example.
8+
This the very conceptual example rewrite from original source code [java example](https://github.com/RefactoringGuru/design-patterns-java/tree/main/src/refactoring_guru/factory_method/example)
9+
10+
### Diagram:
11+
![image](https://user-images.githubusercontent.com/8049534/166105090-a2b490fe-3e3e-44f1-a781-9777023020fb.png)
12+
13+
### Client code:
14+
```dart
15+
late Dialog dialog;
16+
17+
void main() {
18+
configure();
19+
runBusinessLogic();
20+
}
21+
22+
void configure() {
23+
if (Platform.isWindows) {
24+
dialog = WindowsDialog();
25+
} else {
26+
dialog = HtmlDialog();
27+
}
28+
}
29+
30+
void runBusinessLogic() {
31+
dialog.renderWindow();
32+
}
33+
```
34+
35+
### Output:
36+
```
37+
Windows Button
38+
Click! Button says - "Hello World!"
39+
```

0 commit comments

Comments
 (0)