static void Main(string[] args){ var modify = new ModifyWallet(); var wallet = new Wallet(1000); Execute(wallet, modify, new WalletCommand(wallet, WalletAction.Add, 350)); Execute(wallet, modify, new WalletCommand(wallet, WalletAction.Substract, 70)); Execute(wallet, modify, new WalletCommand(wallet, WalletAction.Substract, 200)); Execute(wallet, modify, new WalletCommand(wallet, WalletAction.Add, 50)); Console.WriteLine(wallet); modify.UndoActions(); Console.WriteLine(wallet); }
private static void Execute(Wallet wallet, ModifyWallet modify, ICommand walletCommand){ modify.SetCommand(walletCommand); modify.Invoke(); }