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
/*
 * Service locator design pattern
 */

class ServiceLocator
{
    public static function getProperties()
    {
        return new Property();
    }

    public static function getQuantities()
    {
        return new Quantity();
    }
}

class Property
{
    public function getWeight(){
        return 500;
    }
}

class Quantity
{
    public function getAmount(){
        return 5;
    }
}

class Can {

     public static function weight(){
         $amount     = serviceLocator::getQuantities()->getAmount();
         $unitWeight = serviceLocator::getProperties()->getWeight();
         return $amount * $unitWeight;
     }
}

echo Can::weight();
?>

    

Outputs:


2500



 

© 2018 assessmentee.com