Unique

Delegation

class Coder
{
    public function write($name)
    {
        echo $name . ' finish<br/>';
    }
}
class Manager
{
    protected $_member = array();
    public function __set($name, Coder $value)
    {
        $this->_member[$name] = $value;
    }
    public function work()
    {
        foreach ($this->_member as $name => $coder) {
            $coder->write($name);
        }
    }
}
$manager = new Manager();
$john = new Coder();
$mike = new Coder();
$manager->John = $john;
$manager->Mike = $mike;
$manager->work();

  Delegation是一种设计模式,我翻译它为委派模式。它通过经理类来督促并分配任务给指定的码农来完成代码工作。


转载需经作者允许并注明出处(http://hiunique.com/php/109.html)
来自:Unique

添加评论