Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 52e0ab8

Browse files
Change Command abstract class to an interface.
1 parent ce127e1 commit 52e0ab8

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

‎Command/Command.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<ItemGroup>
4545
<Compile Include="Calculator.cs" />
4646
<Compile Include="Command\CalculatorCommand.cs" />
47-
<Compile Include="Command\Command.cs" />
47+
<Compile Include="Command\ICommand.cs" />
4848
<Compile Include="Program.RealWordCode.cs" />
4949
<Compile Include="Properties\AssemblyInfo.cs" />
5050
<Compile Include="User.cs" />

‎Command/Command/CalculatorCommand.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace DoFactory.GangOfFour.Command.RealWorld
1111
/// <summary>
1212
/// The 'ConcreteCommand' class
1313
/// </summary>
14-
class CalculatorCommand : Command
14+
class CalculatorCommand : ICommand
1515
{
1616
private char _operator;
1717
private int _operand;
@@ -39,13 +39,13 @@ public int Operand
3939
}
4040

4141
// Execute new command
42-
public overridevoid Execute()
42+
public void Execute()
4343
{
4444
_calculator.Operation(_operator, _operand);
4545
}
4646

4747
// Unexecute last command
48-
public overridevoid UnExecute()
48+
public void UnExecute()
4949
{
5050
_calculator.Operation(Undo(_operator), _operand);
5151
}

‎Command/Command/Command.cs‎ renamed to ‎Command/Command/ICommand.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ namespace DoFactory.GangOfFour.Command.RealWorld
88
{
99

1010
/// <summary>
11-
/// The 'Command' abstract class
11+
/// The 'Command' Interface
1212
/// </summary>
13-
abstractclassCommand
13+
interfaceICommand
1414
{
15-
publicabstractvoid Execute();
16-
publicabstractvoid UnExecute();
15+
void Execute();
16+
void UnExecute();
1717
}
1818
}

‎Command/User.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class User
1313
{
1414
// Initializers
1515
private Calculator _calculator = new Calculator();
16-
private List<Command> _commands = new List<Command>();
16+
private List<ICommand> _commands = new List<ICommand>();
1717
private int _current = 0;
1818

1919
public void Redo(int levels)
@@ -24,7 +24,7 @@ public void Redo(int levels)
2424
{
2525
if (_current < _commands.Count - 1)
2626
{
27-
Command command = _commands[_current++];
27+
ICommand command = _commands[_current++];
2828
command.Execute();
2929
}
3030
}
@@ -38,7 +38,7 @@ public void Undo(int levels)
3838
{
3939
if (_current > 0)
4040
{
41-
Command command = _commands[--_current] as Command;
41+
ICommand command = _commands[--_current] as ICommand;
4242
command.UnExecute();
4343
}
4444
}
@@ -47,7 +47,7 @@ public void Undo(int levels)
4747
public void Compute(char @operator, int operand)
4848
{
4949
// Create command operation and execute it
50-
Command command = new CalculatorCommand(
50+
ICommand command = new CalculatorCommand(
5151
_calculator, @operator, operand);
5252
command.Execute();
5353

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /