public static void Test() { //var demo = new DemoClass(); //var command = new SingleCommand(demo, SingleCommand.Action.CommAdd, 20); //command.Call(); //Console.WriteLine(demo); //command.Undo(); //Console.WriteLine(demo); //------------------------------- var demo1 = new DemoClass(); var command1 = new SingleCommand(demo1, SingleCommand.Action.CommAdd, 20); var command2 = new SingleCommand(demo1, SingleCommand.Action.CommAdd, 40); var command3 = new SingleCommand(demo1, SingleCommand.Action.CommRemove, 10); var commands = new CompositeCommand(new[] { command1, command2, command3 }); commands.Call(); Console.WriteLine(demo1); commands.Undo(); Console.WriteLine(demo1); }
public SingleCommand(DemoClass demo, Action action, int amount) { this.demo = demo; this.action = action; this.amount = amount; }