assessmentee.com

Home | Start test | Contact
 

Activerecord | Adapter | Decorator | DependencyInjectionContainer | Facade | Factory | Hydration | Inheritance | Iterator | Mapper | MVC | Observer | Prototype | Proxy | Registry | ServiceLocator | Singleton | Specification | Strategy | TableGateway | ZF1_TableGateway | ZF2_TableGateway |




    <?php
/*
 * Proxy design pattern
 *
 */

class Inventory {

     protected $item;

    public function __construct($item) {
        $this->item = $item;
    }

    protected function getCount(){
        if($this->item == 'banana'){
            return 10;
        }
    }

}

class ProxyInventory extends inventory {

    protected $item;

    public function __construct($item) {
        $this->item = $item;
    }

    public function getCount(){

        static $produce = null;
        if($produce === null){
            $produce = new inventory($this->item);
        }
        return $produce->getCount();
    }

}


$inventory = new ProxyInventory('banana');

echo $inventory->getCount();

?>


    

Outputs:


10



 

© 2018 assessmentee.com