Exemple #1
0
        static void Main(string[] args)
        {
            BankAccount ba       = new BankAccount();
            var         commands = new List <BankAcoountCommand>
            {
                new BankAcoountCommand(ba, BankAcoountCommand.Action.Deposit, 100),
                new BankAcoountCommand(ba, BankAcoountCommand.Action.Withdraw, 1500),
            };

            WriteLine(ba);

            foreach (var c in commands)
            {
                c.Call();
            }

            WriteLine(ba);

            foreach (var c in Enumerable.Reverse(commands))
            {
                c.Undo();
            }

            WriteLine(ba);


            var ba2        = new BankAccount2();
            var cmdDeposit = new BankAccountCommand(ba2,
                                                    BankAccountCommand.Action.Deposit, 100);
            var cmdWithdraw = new BankAccountCommand(ba2,
                                                     BankAccountCommand.Action.Withdraw, 1000);

            cmdDeposit.Call();
            cmdWithdraw.Call();
            WriteLine(ba);
            cmdWithdraw.Undo();
            cmdDeposit.Undo();
            WriteLine(ba);


            var from = new BankAccount2();

            from.Deposit(100);
            var to = new BankAccount2();

            var mtc = new MoneyTransferCommand(from, to, 1000);

            mtc.Call();


            // Deposited $100, balance is now 100
            // balance: 100
            // balance: 0

            WriteLine(from);
            WriteLine(to);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            BankAccount        ba      = new BankAccount(0);
            BankAccountCommand command = new BankAccountCommand(ba, 100, BankAccountCommand.Action.Deposit);

            command.Call();
            BankAccountCommand cmd2 = new BankAccountCommand(ba, 1000, BankAccountCommand.Action.Withdraw);

            command.Call();
            cmd2.Call();

            ReadLine();
        }
        static void Main(string[] args)
        {
            var ba   = new BankAccount();
            var bac1 = new BankAccountCommand(ba, BankAccountCommand.Action.Deposit, 300);
            var bac2 = new BankAccountCommand(ba, BankAccountCommand.Action.Withdraw, 900);

            var commands = new List <BankAccountCommand>();

            commands.Add(bac1);
            commands.Add(bac2);

            foreach (var c in commands)
            {
                c.call();
            }

            foreach (var c in Enumerable.Reverse(commands))
            {
                c.undo();
            }

            Console.ReadLine();
        }