Skip to content

Commit a69760d

Browse files
authored
Merge pull request #28 from ilopX/refacotring-v0.17.17
Refactoring v0.17.17
2 parents 9f58fa6 + 379ed44 commit a69760d

File tree

23 files changed

+227
-190
lines changed

23 files changed

+227
-190
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
## 0.17.16 - refactoring
2+
- Simplifying the ternary construction.
3+
- Remove multiline comment from main README.
4+
- Replace repository urls to relative.
5+
- Fix relative urls.
6+
- Fix name on diagram "Builder", rename JsonFormat to JsonConverter.
7+
- Select pattern "Command" at the diagram.
8+
- Add client code to "Bridge" pattern.
9+
- Fix url position & add example name to ProductsAndBoxes example.
10+
- Add example name to Decorator pattern.
11+
- Format app_observer.dart.
12+
- Connect Application to events on the AppObserver diagram.
13+
- Split into separate files the "Memento" project.
14+
- Remover unnecessary import.
15+
- Move hash generator to application.
16+
- Update SubscriberWidget diagram.
17+
- Fix url position in FlutterAdapter README.md.
18+
119
## 0.17.0
220
Add "Adapter" pattern: adapt a non-reactive classic type application for Flutter.
321

README.md

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@ It contains **Dart** examples for all classic **GoF** design patterns.
44

55
# Implementation checklist:
66
- [ ] **Creation**
7-
- [ ] [**Abstract Factory**](https://refactoring.guru/design-patterns/abstract-factory)
8-
- [x] [**Builder**](https://refactoring.guru/design-patterns/builder) - [[Color Text Format](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/builder/color_text_format)]
9-
- [ ] [**Factory Method**](https://refactoring.guru/design-patterns/factory-method)
10-
- [x] [**Prototype**](https://refactoring.guru/design-patterns/prototype) - [[Shapes](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/prototype/shapes)]
11-
- [ ] [**Singleton**](https://refactoring.guru/design-patterns/singleton)
7+
- [ ] **Abstract Factory**
8+
- [x] **Builder** - [[Color Text Format](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/builder/color_text_format)]
9+
- [ ] **Factory Method**
10+
- [x] **Prototype**] - [[Shapes](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/prototype/shapes)]
11+
- [ ] **Singleton**
1212
- [ ] **Behavioral**
13-
- [x] [**Chain of Responsibility**](https://refactoring.guru/design-patterns/chain-of-esponsibility) - [[Server Middleware](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/chain_of_responsibility/server_middleware)]
14-
- [x] [**Command**](https://refactoring.guru/design-patterns/command) - [[Text Editor](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/command/text_editor)]
13+
- [x] **Chain of Responsibility** - [[Server Middleware](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/chain_of_responsibility/server_middleware)]
14+
- [x] **Command** - [[Text Editor](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/command/text_editor)]
1515
- [ ] Interpreter
16-
- [ ] [**Iterator**](https://refactoring.guru/design-patterns/iterator)
17-
- [ ] [**Mediator**](https://refactoring.guru/design-patterns/mediator)
18-
- [x] [**Memento**](https://refactoring.guru/design-patterns/memento) - [[Conceptual](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/memento/conceptual)]
19-
- [x] [**Observer**](https://refactoring.guru/design-patterns/observer) - [[Open-Close Editor Events](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/observer/open_close_editor_events)] [[AppObserver](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/observer/app_observer)] [[Subscriber Flutter Widget](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/observer/subscriber_flutter_widget)]
20-
- [ ] [**State**](https://refactoring.guru/design-patterns/state)
21-
- [ ] [**Template Method**](https://refactoring.guru/design-patterns/template-method)
22-
- [ ] [**Visitor**](https://refactoring.guru/design-patterns/visitor)
23-
- [ ] [**Strategy**](https://refactoring.guru/design-patterns/strategy)
16+
- [ ] **Iterator**
17+
- [ ] **Mediator**
18+
- [x] **Memento** - [[Conceptual](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/memento/conceptual)]
19+
- [x] **Observer** - [[Open-Close Editor Events](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/observer/open_close_editor_events)] [[AppObserver](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/observer/app_observer)] [[Subscriber Flutter Widget](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/observer/subscriber_flutter_widget)]
20+
- [ ] **State**
21+
- [ ] **Template Method**
22+
- [ ] **Visitor**
23+
- [ ] **Strategy**
2424
- [ ] **Structural**
25-
- [x] [**Adapter**](https://refactoring.guru/design-patterns/adapter) - [[Text Graphics](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/adapter/text_graphics)] [[Square Round conflict](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/adapter/square_round_conflict)] [[Flutter Adapter](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/adapter/flutter_adapter)]
26-
- [x] [**Bridge**](https://refactoring.guru/design-patterns/bridge) - [[Remote Device Control](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/bridge/devices_remote_control)] [[Clock](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/bridge/clock)]
27-
- [x] [**Composite**](https://refactoring.guru/design-patterns/composite) - [[Image Editor](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/composite/image_editor)] [[Products and Boxes](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/composite/products_and_boxes)]
28-
- [x] [**Decorator**](https://refactoring.guru/design-patterns/decorator) - [[Data Source Decoder](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/decorator/data_source_decoder)]
29-
- [ ] [**Facade**](https://refactoring.guru/design-patterns/facade)
30-
- [ ] [**Flyweight**](https://refactoring.guru/design-patterns/flyweight)
31-
- [ ] [**Proxy**](https://refactoring.guru/design-patterns/proxy)
25+
- [x] **Adapter** - [[Text Graphics](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/adapter/text_graphics)] [[Square Round conflict](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/adapter/square_round_conflict)] [[Flutter Adapter](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/adapter/flutter_adapter)]
26+
- [x] **Bridge** - [[Remote Device Control](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/bridge/devices_remote_control)] [[Clock](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/bridge/clock)]
27+
- [x] **Composite** - [[Image Editor](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/composite/image_editor)] [[Products and Boxes](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/composite/products_and_boxes)]
28+
- [x] **Decorator** - [[Data Source Decoder](https://github.com/RefactoringGuru/design-patterns-dart/tree/master/patterns/decorator/data_source_decoder)]
29+
- [ ] **Facade**
30+
- [ ] **Flyweight**
31+
- [ ] **Proxy**
3232

3333
## Requirements
3434

@@ -50,20 +50,16 @@ Here's a style guide which might help you to keep your changes consistent with o
5050
4. File names should match following convention: `some_class_name.dart`
5151

5252
5. Comments may or may not have language tags in them, such as this:
53-
5453
```dart
55-
/**
56-
* EN: All products families have the same varieties (MacOS/Windows).
57-
*
58-
* This is a MacOS variant of a button.
59-
*
60-
* RU: Все семейства продуктов имеют одни и те же вариации (MacOS/Windows).
61-
*
62-
* Это вариант кнопки под MacOS.
63-
*/
54+
// EN: All products families have the same varieties (MacOS/Windows).
55+
// This is a MacOS variant of a button.
56+
57+
// RU: Все семейства продуктов имеют одни и те же вариации (MacOS/Windows).
58+
// Это вариант кнопки под MacOS.
6459
```
65-
66-
Don't be scared and ignore the non-English part of such comments. If you want to change something in a comment like this, then do it. Even if you do it wrong, we'll tell you how to fix it during the Pull Request.
60+
Don't be scared and ignore the non-English part of such comments. If you want to change
61+
something in a comment like this, then do it. Even if you do it wrong, we'll tell you how
62+
to fix it during the Pull Request.
6763
6864
6965
### Build Flutter examples
@@ -73,7 +69,7 @@ flutter build web -t bin\main.dart --web-renderer html
7369
```
7470

7571
### Deploy flutter demos
76-
1. Fork this repo: https://github.com/RefactoringGuru/design-patterns-dart
72+
1. Fork this repo: `https://github.com/RefactoringGuru/design-patterns-dart`
7773
2. Apply your changes.
7874
3. Run the script `dart bin\deploy_flutter_demos.dart`.
7975
This script will build a web platform flutter app and push the changes to your **web-demos** branch on github.

patterns/adapter/flutter_adapter/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,8 @@ This complex example includes these implementations:
1414

1515
### Online demo:
1616
Click on the picture to see a [demo](https://refactoringguru.github.io/design-patterns-dart/#/adapter/flutter_adapter).
17-
[![image](https://user-images.githubusercontent.com/8049534/152689272-d4bed484-e216-4eda-8833-928ada7d4051.png)](https://refactoringguru.github.io/design-patterns-dart/#/adapter/flutter_adapter)
18-
19-
### Diagram:
20-
![image](https://user-images.githubusercontent.com/8049534/152753162-1b9006ad-a633-4132-91b6-bb348559adec.png)
21-
22-
### Sequence [Classic application -> Change Text color]
23-
When user clicked to "Flutter Adapter" text.
2417

25-
![image](https://user-images.githubusercontent.com/8049534/152753714-84af5abd-85c0-4845-af2d-616f512ef633.png)
26-
27-
### Sequence [Flutter Widget -> Change Text color]
28-
When the user has selected a color in the color bar.
29-
30-
![image](https://user-images.githubusercontent.com/8049534/152753870-edeab3ae-8e79-4e9d-9049-7cd5a2100afa.png)
18+
[![image](https://user-images.githubusercontent.com/8049534/152689272-d4bed484-e216-4eda-8833-928ada7d4051.png)](https://refactoringguru.github.io/design-patterns-dart/#/adapter/flutter_adapter)
3119

3220
### Client code:
3321
```dart
@@ -56,5 +44,17 @@ void main() {
5644
classicApp: app,
5745
);
5846
}
59-
6047
```
48+
49+
### Diagram:
50+
![image](https://user-images.githubusercontent.com/8049534/152753162-1b9006ad-a633-4132-91b6-bb348559adec.png)
51+
52+
### Sequence [Classic application -> Change Text color]
53+
When user clicked to "Flutter Adapter" text.
54+
55+
![image](https://user-images.githubusercontent.com/8049534/152753714-84af5abd-85c0-4845-af2d-616f512ef633.png)
56+
57+
### Sequence [Flutter Widget -> Change Text color]
58+
When the user has selected a color in the color bar.
59+
60+
![image](https://user-images.githubusercontent.com/8049534/152753870-edeab3ae-8e79-4e9d-9049-7cd5a2100afa.png)

patterns/bridge/devices_remote_control/README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,37 @@
22
This example rewrite from [java example](https://github.com/RefactoringGuru/design-patterns-java/tree/master/src/refactoring_guru/bridge/example)
33
But removed the ability to use null for devices. Instead, the EmptyDevice class is used.
44

5-
**Diagram:**
5+
### Remote device example
6+
7+
Example describe this: https://refactoring.guru/design-patterns/bridge?#pseudocode
8+
9+
### Diagram:
610

711
![image](https://user-images.githubusercontent.com/8049534/145878324-3cbc52f5-51f4-4642-921d-69fbe2886f8c.png)
812

9-
**Description:**
13+
### Client code:
14+
```dart
15+
void main() {
16+
testDevice(Tv());
17+
testDevice(Radio());
18+
testDevice(EmptyDevice());
19+
}
1020
11-
https://refactoring.guru/design-patterns/bridge?#pseudocode
21+
void testDevice(Device device) {
22+
print(''.padRight(36, '='));
23+
print(device.runtimeType);
24+
print("Tests with basic remote.");
25+
final basicRemote = BasicRemote.fromDevice(device);
26+
basicRemote.power();
27+
device.printStatus();
28+
29+
print("Tests with advanced remote.");
30+
final advancedRemote = AdvancedRemote.fromDevice(device);
31+
advancedRemote.power();
32+
advancedRemote.mute();
33+
device.printStatus();
34+
}
35+
```
1236

1337
**Output:**
1438

patterns/builder/color_text_format/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ https://refactoring.guru/design-patterns/builder
88
Using different text formats.
99

1010
### Class diagram
11-
![image](https://user-images.githubusercontent.com/8049534/146023073-5d7644a4-d3b9-4420-bffe-f72ac3fd83dd.png)
11+
![image](https://user-images.githubusercontent.com/8049534/152780645-4eed27fc-a483-432e-99b0-4a77f2adbd5d.png)
1212

1313
### Client code:
1414
```dart

patterns/command/text_editor/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ But slightly changed, see the class diagram.
1717
## Diagram:
1818
![image](https://user-images.githubusercontent.com/8049534/149918792-fccae912-2e67-4068-88d1-5cf824f0df2c.png)
1919

20-
## Client code:
20+
### Client code:
2121
```dart
2222
void main() {
2323
final app = Application();

patterns/command/text_editor/application/editor.dart

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,10 @@ class Editor {
6262

6363
@override
6464
String toString() {
65-
return cursor.isTextSelected
66-
? _text.replaceRange(
67-
cursor.startSelection,
68-
cursor.endSelection,
69-
'[$selectedText]',
70-
)
71-
: _text.replaceRange(
72-
cursor.position,
73-
cursor.position,
74-
'|',
75-
);
65+
return _text.replaceRange(
66+
cursor.startSelection,
67+
cursor.endSelection,
68+
cursor.isTextSelected ? '[$selectedText]' : '|',
69+
);
7670
}
7771
}

patterns/composite/image_editor/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ https://refactoring.guru/design-patterns/composite?#pseudocode
77
## Origin source code:
88
This example rewrite from [java example](https://github.com/RefactoringGuru/design-patterns-java/tree/master/src/refactoring_guru/composite/example)
99

10-
## Diagram:
10+
### Diagram:
1111
![image](https://user-images.githubusercontent.com/8049534/149174388-25ca21b1-d762-40b5-a853-528abe18b66c.png)
1212

13-
**Client code:**
13+
### Client code:
1414
```dart
1515
void main() {
1616
final editor = ImageEditor();

patterns/composite/products_and_boxes/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
Composite is a structural design pattern that lets you compose objects into tree structures and then
33
work with these structures as if they were individual objects.
44

5-
## Problem description:
5+
## Example: Products and boxes
66
![problem-en](https://user-images.githubusercontent.com/8049534/147579298-0c60c4a7-6acb-4ab3-a973-e06524c5a061.png)
7-
https://refactoring.guru/design-patterns/composite?#problem
7+
8+
For example, imagine that you have two types of objects: Products and Boxes. A Box can contain
9+
several Products as well as a number of smaller Boxes. These little Boxes can also hold some
10+
Products or even smaller Boxes, and so on.
11+
12+
Full description can be found [here](https://refactoring.guru/design-patterns/composite?#problem)
813

914
### Folder description:
1015
- `/products` - represent product and box (composite pattern)

patterns/composite/products_and_boxes/diagram/diagram.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:design_patterns_dart/text_canvas.dart';
2-
import 'package:design_patterns_dart/text_canvas/primitives.dart';
32

43
import '../products/product.dart';
54
import '../render_elements/render_connecting_lines.dart';

0 commit comments

Comments
 (0)