Skip to content

Commit 2ef4056

Browse files
committed
Add README.
1 parent 038e3af commit 2ef4056

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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/state).
6+
7+
### Diagram:
8+
![image](https://user-images.githubusercontent.com/8049534/172000870-a96c6dd2-5b6a-4a64-b3a9-4edb75dd8076.png)
9+
10+
### Client code:
11+
```dart
12+
void main() {
13+
final switcher = Switcher(
14+
initState: One(),
15+
);
16+
17+
switcher.call(); // call(1): One
18+
switcher.call(); // call(2): Two
19+
switcher.call(); // call(3): Three
20+
switcher.call(); // call:(4) One
21+
}
22+
```

0 commit comments

Comments
 (0)