Skip to content

Commit 2a2b5eb

Browse files
committed
Add client code & output to README.
1 parent d945b5e commit 2a2b5eb

File tree

1 file changed

+45
-0
lines changed
  • patterns/abstract_factory/conceptual_gui_factory

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Memento pattern
2+
Memento is a behavioral design pattern that lets you save and restore the previous state of an
3+
object without revealing the details of its implementation.
4+
5+
Tutorial: [here](https://refactoring.guru/design-patterns/memento).
6+
7+
### Online demo:
8+
Click on the picture to see the [demo](https://RefactoringGuru.github.io/design-patterns-dart/#/memento/flutter_memento_editor).
9+
10+
[![image](https://user-images.githubusercontent.com/8049534/165401175-88bc4593-4624-45b4-8c03-6f1390ed771a.png)](https://refactoringguru.github.io/design-patterns-dart/#/memento/flutter_memento_editor)
11+
12+
### Dependency Patterns
13+
This complex example includes these implementations:
14+
- [[AppObserver](https://github.com/RefactoringGuru/design-patterns-dart/tree/main/patterns/observer/app_observer)]
15+
- [[SubscriberWidget](https://github.com/RefactoringGuru/design-patterns-dart/tree/main/patterns/observer/subscriber_flutter_widget)]
16+
17+
### Diagram:
18+
![image](https://user-images.githubusercontent.com/8049534/165758516-1de543f5-666d-4e07-958d-2d8fceb73af9.png)
19+
20+
### Client code:
21+
```dart
22+
void main() {
23+
final guiFactory = GUIFactory();
24+
final app = Application(guiFactory);
25+
app.paint();
26+
}
27+
28+
abstract class GUIFactory {
29+
factory GUIFactory() {
30+
if (Platform.isMacOS) {
31+
return MacOSFactory();
32+
} else {
33+
return WindowsFactory();
34+
}
35+
}
36+
37+
/*...*/
38+
}
39+
```
40+
41+
### Output:
42+
```
43+
You have created WindowsButton.
44+
You have created WindowsCheckbox.
45+
```

0 commit comments

Comments
 (0)