File tree Expand file tree Collapse file tree 2 files changed +79
-0
lines changed
Expand file tree Collapse file tree 2 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -26,3 +26,4 @@ Full Playlist can be found [here](https://www.youtube.com/playlist?list=PLOeFnOV
2626### Behavioral Patterns
2727
2828- [ Iterator] ( https://youtu.be/Gco6zF_ygSc )
29+ - [ Chain of Responsibility] ( https://youtu.be/YQ03IyRu1Zo )
Original file line number Diff line number Diff line change 1+ < Query Kind = "Program" / >
2+
3+ void Main ( )
4+ {
5+ // select code in editor tab
6+ var ide = new IDE ( null ) ;
7+ var editor = new CodeEditor ( ide ) ;
8+ var codeSelection = new CodeSelection ( editor ) ;
9+
10+ codeSelection . HandleKey ( "Ctrl+F" ) ;
11+ codeSelection . HandleKey ( "Alt+F4" ) ;
12+ }
13+
14+ interface IKeyHandler
15+ {
16+ void HandleKey ( string key ) ;
17+ }
18+
19+ class IDE : IKeyHandler
20+ {
21+ IKeyHandler _handler ;
22+
23+ public IDE ( IKeyHandler handler ) => _handler = handler ;
24+
25+ public void HandleKey ( string key )
26+ {
27+ if ( key == "Ctrl+F" )
28+ {
29+ "Full Search" . Dump ( ) ;
30+ }
31+ else if ( key == "Alt+F4" )
32+ {
33+ "Close Application?" . Dump ( ) ;
34+ }
35+ else
36+ {
37+ _handler ? . HandleKey ( key ) ;
38+ }
39+ }
40+ }
41+
42+ class CodeEditor : IKeyHandler
43+ {
44+ IKeyHandler _handler ;
45+
46+ public CodeEditor ( IKeyHandler handler ) => _handler = handler ;
47+
48+ public void HandleKey ( string key )
49+ {
50+ if ( key == "Ctrl+F" )
51+ {
52+ "Local Search" . Dump ( ) ;
53+ }
54+ else
55+ {
56+ _handler ? . HandleKey ( key ) ;
57+ }
58+ }
59+ }
60+
61+ class CodeSelection : IKeyHandler
62+ {
63+ IKeyHandler _handler ;
64+
65+ public CodeSelection ( IKeyHandler handler ) => _handler = handler ;
66+
67+ public void HandleKey ( string key )
68+ {
69+ if ( key == "Ctrl+F" )
70+ {
71+ "Selection Search" . Dump ( ) ;
72+ }
73+ else
74+ {
75+ _handler ? . HandleKey ( key ) ;
76+ }
77+ }
78+ }
You can’t perform that action at this time.
0 commit comments