Skip to content

Commit 1e52f59

Browse files
committed
Add project README.
1 parent 61eb1c4 commit 1e52f59

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Strategy Pattern
2+
Strategy is a behavioral design pattern that lets you define a family of algorithms, put each of
3+
them into a separate class, and make their objects interchangeable.
4+
5+
Tutorial: [here](https://refactoring.guru/design-patterns/strategy).
6+
7+
## Diagram:
8+
![image](https://user-images.githubusercontent.com/8049534/175562829-c91fbb12-50ac-4373-a33f-900527383a6c.png)
9+
10+
## Client code:
11+
```dart
12+
void main() {
13+
final byteList = ByteContext()
14+
..add('Hello guru')
15+
..add(123456789)
16+
..add(3.1456564984);
17+
18+
final strFormat = byteList.toStringView(StrViewStrategy());
19+
final hexFormat = byteList.toStringView(HexViewStrategy());
20+
final zipFormat = byteList.toStringView(ZipViewStrategy());
21+
22+
print(strFormat);
23+
print(hexFormat);
24+
print(zipFormat);
25+
}
26+
```
27+
28+
### Output:
29+
```
30+
StrViewStrategy:
31+
Hello guru, 123456789, 3.1456564984
32+
33+
HexViewStrategy:
34+
Hello guru : 48 65 6c 6c 6f 20 67 75 72 75
35+
123456789 : 00 00 00 00 07 5b cd 15
36+
3.1456564984 : 40 09 2a 4d f4 48 9f 7e
37+
38+
ZipViewStrategy:
39+
1f 8b 08 00 00 00 00 00 00 0a f3 48 cd c9 c9 57
40+
48 2f 2d 2a d5 51 30 34 32 36 31 35 33 b7 b0 d4
41+
51 30 d6 33 04 32 4d cd 4c 2c 2d 4c b8 00 d4 70
42+
cf ee 24 00 00 00
43+
```

0 commit comments

Comments
 (0)