Рубрики
Uncategorized

Шаблон адаптера шаблона дизайна PHP

Автор оригинала: David Wong.

Разберитесь в своем исследовании, которое написал Аарон Сарай Шаблон дизайна PHP некоторые демо И ваше собственное понимание. После прочтения, если вы обнаружите, что я понимаю это неправильно, пожалуйста, немедленно укажите, спасибо, что хлопаете по кирпичам, становитесь на колени и просите о порке

/**
 *Adapter adapter mode
 * -------------------------------------
 ** from description**
 * 
 *Through the adapter pattern, new code and functionality can be used to help update the original system.
 *Simply put, when you need to convert an object's interface to another object,
 *The adapter mode can be adopted without changing the original object
 * 
 * ===================================== 
 ** application scenarios**
 *
 *Use when making interface changes to the base classes of the old schema in the project 
 * 
 * -------------------------------------
 * 
 * @version ${Id}$
 * @author Shaowei Pu <[email protected]>
 */
php

//You are now a mining foreman assigned by Dawei construction team to Iran.

/**
 *Dawei construction team headquarters
 */
class headquarters  
{
    protected $_worker;
    public function __construct($worker){
        $this->_worker = $worker;
    }
    public function getWorker(){
        if( !empty($this->_worker) ){
            Return 'great power'. $this - >;
        }
    }
}
/**
 *Subcontracted out to work
 */
class assignWorker
{
    protected $_workerObject;
    public function __construct(headquarters $_workerObject ){
        $this->_workerObject = $_workerObject;
    }
    public function assign(){
        Echo $this - >
    }
}

/**
 *Now you need 20 great brick movers. Then you can find the headquarters and the headquarters will give you
 */
$Iran   = new assignWorker(new headquarters(20));
$Iran->assign();
echo "
"; //Day after day, year after year, you are transferred to Lebanon to mine. This is different from your days in Iran. Here you are going to mine diamonds //But this diamond mine needs several bricklayers to cooperate with the mining master, but the company can't provide other departments to you now, because we are a century old enterprise, the main unit can't add departments at will //Dawei International's talent training is very efficient. It's hard not to beat you if you want anything. So you figured out a way // /** *Dedicated adapter for Lebanon */ class Adapter extends headquarters { public function __construct($worker){ parent::__construct($worker); $this->getallheaders(); } public function getallheaders(){ $this - >; } } //Now the people you want come out $Lebanon = new assignWorker(new Adapter(20)); $Lebanon->assign();