File tree Expand file tree Collapse file tree
BehavioralDesignPattern/CommandPattern/CSharp/CommandPatternDemo Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Text ;
4+
5+ namespace CommandPattern
6+ {
7+ class CommandPatternDemo
8+ {
9+ static void Main ( string [ ] args )
10+ {
11+ Invoker tInvoker = new Invoker ( ) ;
12+ ReceiveRole tRole = new ReceiveRole ( ) ;
13+ MoveForwardCommand tMoveForwardCommand = new MoveForwardCommand ( tRole ) ;
14+ TurnLeftCommand tTurnLeftCommand = new TurnLeftCommand ( tRole ) ;
15+ TurnRightCommand tTurnRightCommand = new TurnRightCommand ( tRole ) ;
16+ AttackCommand tAttackCommand = new AttackCommand ( tRole ) ;
17+
18+ // set command list
19+ tInvoker . SetCommand ( tTurnLeftCommand ) ;
20+ tInvoker . SetCommand ( tMoveForwardCommand ) ;
21+ tInvoker . SetCommand ( tMoveForwardCommand ) ;
22+ tInvoker . SetCommand ( tTurnRightCommand ) ;
23+ tInvoker . SetCommand ( tMoveForwardCommand ) ;
24+ tInvoker . SetCommand ( tAttackCommand ) ;
25+
26+ // Notify the role to execute command
27+ tInvoker . NotifyExecute ( ) ;
28+
29+ Console . ReadKey ( ) ;
30+ }
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments