using System; namespace FacadePattern { public class BankSubsystem : IBankSubsystem { /// /// 查询余额 /// /// 银行账户 /// public int CheckBalance(BankAccount account) { return account.TotalMoney; } /// /// 取款 /// /// 银行账户 /// 取多少钱 /// 余额 public bool WithdrewMoney(BankAccount account, int money) { if (account.TotalMoney >= money) account.TotalMoney -= money; else throw new Exception("余额不足!"); return true; } /// /// 转账 /// /// 转出账户 /// 目标账户 /// 转多少钱 /// public bool TransferMoney(BankAccount account, string targetNo, int money) { var targetAccount = AccountSubsystem.GetAccount(targetNo); if (targetAccount == null) throw new Exception("目标账户不存在!"); if (account.TotalMoney < money) throw new Exception("余额不足!"); account.TotalMoney -= money; targetAccount.TotalMoney += money; return true; } /// /// 存款 /// /// 银行账户 /// 存多少钱 /// public bool DepositMoney(BankAccount account, int money) { account.TotalMoney += money; return true; } /// /// 充值话费 /// /// 手机号 /// 银行账户 /// 充值多少 /// public bool RechargeMobilePhone(BankAccount account, string phoneNumber, int money) { throw new NotImplementedException(); } } }