1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| class Bank{ protected $info;
public function updateBrankInfo($type,$money){ $this->info[$type]=$money; }
public function brankWithdraw($branktype){ $obj=new $branktype; return $obj->brankMain($this->info); } }
/* 委托接口 */ interface Delegate{ public function brankMain($info); }
/* 存款操作类 */ class brankDeposit implements Delegate{
public function brankMain($info){ echo $info['deposit']; } }
/* 取款操作类 */ class brankWithdraw implements Delegate{ public function brankMain($info){ echo $info['withdraw']; } }
$bank=new Bank(); $bank->updateBrankInfo("deposit","4000"); $bank->updateBrankInfo("withdraw","2000"); $bank->brankWithdraw("brankDeposit"); echo "<br>"; $bank->brankWithdraw("brankWithdraw");
|