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

/*
 * Specification design pattern
 */

class Stock {
    public function getStock() {
        return 8;
    }
}

class Price {
    public function getPrice() {
        return 8;
    }
}

class Quality {
   public function getQuality() {
        return 8;
    }
}

class Availability {

    public $stock;
    public $price;
    public $quality;

    public function __construct($stock, $price, $quality) {
        $this->stock = $stock;
        $this->price = $price;
        $this->quality = $quality;
    }

}

class buyMe {

    public function isSatisfiedBy($availability){
        if ($availability->stock->getStock() < 5
                || $availability->price->getPrice() > 15
                        || $availability->quality->getQuality() < 5) {
            return false;
        }
        return true;
    }
}

$stock = new Stock();
$price = new Price();
$quality = new Quality();

$availability = new Availability($stock, $price, $quality);
$buyMe = new buyMe();
echo ($buyMe->isSatisfiedBy($availability))?"Buy!":"Do not buy";

?>

    

Outputs:


Buy!



 

© 2018 assessmentee.com