Beispiel #1
0
        static void Main(string[] args)
        {
            BankAccount account   = new BankAccount();                          //创建银行账号
            Command     commandIn = new MoneyInCommand(account, 500);           //创建一个存款500的命令
            Invoker     invoker   = new Invoker();                              // 创建一个调度者

            invoker.SetCommand(commandIn);                                      //调度一个 存款 命令
            invoker.ExecuteCommand();                                           //执行刚调度的命令

            Command commandIn2 = new MoneyInCommand(account, 500);              //创建一个 再次 存入 500元 的命令

            invoker.SetCommand(commandIn2);                                     //调度这个 又存入500元的 命令
            invoker.ExecuteCommand();                                           //执行刚调度的命令

            Command commandOut = new MoneyOutCommand(account, 300);             //创建一个 取款 300元 的命令

            invoker.SetCommand(commandOut);                                     //调度一个 取款命令
            invoker.ExecuteCommand();                                           //执行刚调度的命令

            Command commandTransferIn = new TransferInCommand(account, 8000);   //创建一个 转入 8000元 的命令

            invoker.SetCommand(commandTransferIn);                              //调度这个 转入命令
            invoker.ExecuteCommand();                                           //执行刚调度的命令

            Command commandTransferOut = new TransferOutCommand(account, 1500); //穿件一个 转出 1500元 的命令

            invoker.SetCommand(commandTransferOut);                             //调度这个 转出命令
            invoker.ExecuteCommand();                                           //执行刚调度的命令

            //AlipayAccount alipayAccount = new AlipayAccount();
            //Command alipayIn = new AlipayAccountMoneyInCommand(alipayAccount, 8888);
            //AlipayUser alipayUser = new AlipayUser();

            //alipayUser.SetCommand(alipayIn);
            //alipayUser.ExecuteCommand();

            AlipayAccount alipayAccount = new AlipayAccount();
            Command       alipayIn      = new AlipayAccountMoneyInCommand(alipayAccount, 8888);
            Invoker       alipayUser    = new Invoker();

            alipayUser.SetCommand(alipayIn);
            alipayUser.ExecuteCommand();

            Command alipayAccountTransferInCommand = new AlipayAccountTransferInCommand(alipayAccount, 5000);

            alipayUser.SetCommand(alipayAccountTransferInCommand);
            alipayUser.ExecuteCommand();

            Console.Read();
        }
 /// <summary>
 /// 重构/重写:重构抽象类Command中的抽象方法Execute 姜彦20180228 17:34 C#重构与重写似乎是一个概念?
 /// </summary>
 public override void Execute()
 {
     //throw new NotImplementedException();
     AlipayAccount.TransferIn(_amount);
 }
 public AlipayAccountTransferInCommand(AlipayAccount account, decimal amount) : base(account)
 {
     this._amount = amount;
 }
Beispiel #4
0
 public Command(AlipayAccount account)
 {
     this.AlipayAccount = account;
 }
Beispiel #5
0
 /// <summary>
 /// 重构/重写:重构抽象类Command中的抽象方法Execute 姜彦20180228 16:34 C#重构与重写似乎是一个概念?
 /// </summary>
 public override void Execute()
 {
     //_individualAccount.MoneyIn(amount);
     AlipayAccount.MoneyIn(amount);
 }
Beispiel #6
0
 public AlipayAccountMoneyInCommand(AlipayAccount account, decimal amount)
     : base(account)
 {
     this.amount = amount;
 }