首页 > 代码库 > 委托模式

委托模式

通过分配或委托至其他对象,委托设计模式能够去除核心对象中的判决和复杂的功能性

<?php

class brank{

protected $info = array();

public function updateBrankinfo($type, $money)

{

$this->info[$type]=$money;

}

//运行委托模式  操作类型 操作金额 

public function brankWithDraw($branktype){

$obj = new $branktype;

return $obj->brankMain($this->Info);

}

}

class brankDeposit{

public function brankMain($data){

return $data[‘brankDeposit‘];

}

}

class brankWithdraw{

public function brankMain($data){

return $data[‘brankWithdraw‘];

}

}

$brank=new brank();

$brank->updateBrankInfo(‘credit‘,‘积分名称‘);

$brank->updateBrankInfo(‘brankDeposit‘, $money);

$brankreturn=$brank->brankWithdraw(‘brankDeposit‘);//操作存款类

$brankreturn=$brank->brankWithdraw(‘brankDeposit‘);


本文出自 “php学习” 博客,谢绝转载!