File tree 4 files changed +12
-12
lines changed
4 files changed +12
-12
lines changed Original file line number Diff line number Diff line change 44
44
<ItemGroup >
45
45
<Compile Include =" Calculator.cs" />
46
46
<Compile Include =" Command\CalculatorCommand.cs" />
47
- <Compile Include =" Command\Command .cs" />
47
+ <Compile Include =" Command\ICommand .cs" />
48
48
<Compile Include =" Program.RealWordCode.cs" />
49
49
<Compile Include =" Properties\AssemblyInfo.cs" />
50
50
<Compile Include =" User.cs" />
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ namespace DoFactory.GangOfFour.Command.RealWorld
11
11
/// <summary>
12
12
/// The 'ConcreteCommand' class
13
13
/// </summary>
14
- class CalculatorCommand : Command
14
+ class CalculatorCommand : ICommand
15
15
{
16
16
private char _operator ;
17
17
private int _operand ;
@@ -39,13 +39,13 @@ public int Operand
39
39
}
40
40
41
41
// Execute new command
42
- public override void Execute ( )
42
+ public void Execute ( )
43
43
{
44
44
_calculator . Operation ( _operator , _operand ) ;
45
45
}
46
46
47
47
// Unexecute last command
48
- public override void UnExecute ( )
48
+ public void UnExecute ( )
49
49
{
50
50
_calculator . Operation ( Undo ( _operator ) , _operand ) ;
51
51
}
Original file line number Diff line number Diff line change @@ -8,11 +8,11 @@ namespace DoFactory.GangOfFour.Command.RealWorld
8
8
{
9
9
10
10
/// <summary>
11
- /// The 'Command' abstract class
11
+ /// The 'Command' Interface
12
12
/// </summary>
13
- abstract class Command
13
+ interface ICommand
14
14
{
15
- public abstract void Execute ( ) ;
16
- public abstract void UnExecute ( ) ;
15
+ void Execute ( ) ;
16
+ void UnExecute ( ) ;
17
17
}
18
18
}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ class User
13
13
{
14
14
// Initializers
15
15
private Calculator _calculator = new Calculator ( ) ;
16
- private List < Command > _commands = new List < Command > ( ) ;
16
+ private List < ICommand > _commands = new List < ICommand > ( ) ;
17
17
private int _current = 0 ;
18
18
19
19
public void Redo ( int levels )
@@ -24,7 +24,7 @@ public void Redo(int levels)
24
24
{
25
25
if ( _current < _commands . Count - 1 )
26
26
{
27
- Command command = _commands [ _current ++ ] ;
27
+ ICommand command = _commands [ _current ++ ] ;
28
28
command . Execute ( ) ;
29
29
}
30
30
}
@@ -38,7 +38,7 @@ public void Undo(int levels)
38
38
{
39
39
if ( _current > 0 )
40
40
{
41
- Command command = _commands [ -- _current ] as Command ;
41
+ ICommand command = _commands [ -- _current ] as ICommand ;
42
42
command . UnExecute ( ) ;
43
43
}
44
44
}
@@ -47,7 +47,7 @@ public void Undo(int levels)
47
47
public void Compute ( char @operator , int operand )
48
48
{
49
49
// Create command operation and execute it
50
- Command command = new CalculatorCommand (
50
+ ICommand command = new CalculatorCommand (
51
51
_calculator , @operator , operand ) ;
52
52
command . Execute ( ) ;
53
53
You can’t perform that action at this time.
0 commit comments