File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
patterns/command/conceptul Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Command Pattern
2
+ Command is a behavioral design pattern that turns a request into a stand-alone object that contains
3
+ all information about the request.
4
+
5
+ Tutorial: [ here] ( https://refactoring.guru/design-patterns/command ) .
6
+
7
+ ## Diagram:
8
+ ![ image] ( https://user-images.githubusercontent.com/8049534/183062798-c2e9207d-850c-47b6-bbba-3d669299d69f.png )
9
+
10
+ ## Client dode:
11
+ ``` dart
12
+ void main() {
13
+ final mutStr = MutStr();
14
+
15
+ final input1 = AddTextCommand('One', mutStr);
16
+ final input2 = AddTextCommand('Three', mutStr);
17
+ final input3 = InsertTextCommand(' Two ', mutStr, pos: 2);
18
+
19
+ input1.execute();
20
+ print('text = $mutStr'); // mutStr = "One"
21
+
22
+ input2.execute();
23
+ print('text = $mutStr'); // mutStr = "OneThree"
24
+
25
+ input3.execute();
26
+ print('text = $mutStr'); // mutStr = "One Two Three"
27
+
28
+ input3.undo();
29
+ print('text = $mutStr'); // mutStr = "OneThree"
30
+
31
+ input2.undo();
32
+ print('text = $mutStr'); // mutStr = "One "
33
+
34
+ input1.undo();
35
+ print('text = $mutStr'); // mutStr = ""
36
+ }
37
+ ```
38
+
39
+ ### Output:
40
+ ```
41
+ text = One
42
+ text = OneThree
43
+ text = One Two Three
44
+ text = OneThree
45
+ text = One
46
+ text =
47
+ ```
You can’t perform that action at this time.
0 commit comments