Skip to content

Commit 9359711

Browse files
committed
Add README.
1 parent ef3bd18 commit 9359711

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# State Pattern
2+
State is a behavioral design pattern that lets an object alter its behavior when its internal state
3+
changes. It appears as if the object changed its class.
4+
5+
Tutorial: [here](https://refactoring.guru/design-patterns/mediator).
6+
7+
## Diagram:
8+
![image](https://user-images.githubusercontent.com/8049534/173237874-971dd4e7-2e74-4cac-bcea-77b88255adad.png)
9+
10+
### Client code:
11+
```dart
12+
void main() {
13+
final component1 = Component1();
14+
final component2 = Component2();
15+
16+
ConcreteMediator(component1, component2);
17+
18+
component1.doOne();
19+
print('');
20+
component2.doTwo();
21+
}
22+
```
23+
24+
### Output:
25+
```
26+
call Component1.doOne()
27+
ConcreteMediator.notify(event: "doOne")
28+
ConcreteMediator.reactComponentOne()
29+
use component2.name = "Two"
30+
31+
call Component2.doTwo()
32+
ConcreteMediator.notify(event: "doTwo")
33+
ConcreteMediator.reactComponentTwo()
34+
use component1.sate = "Cmp1"
35+
```
36+

0 commit comments

Comments
 (0)