Ejemplo n.º 1
0
    }
    public function getCost()
    {
        return 10 + $this->carService->getCost();
    }
    public function getDescription()
    {
        return "oil change car service" . " and " . $this->carService->getDescription();
    }
}
class TireRotation implements CarService
{
    protected $carService;
    public function __construct(CarService $carService)
    {
        $this->carService = $carService;
    }
    public function getCost()
    {
        return 5 + $this->carService->getCost();
    }
    public function getDescription()
    {
        return "tire change car service" . " and " . $this->carService->getDescription();
    }
}
//$object = new BaseCarService();
//$object = new OilChange(new BaseCarService());
$object = new TireRotation(new OilChange(new BaseCarService()));
echo $object->getDescription() . "\n";
echo $object->getCost() . "\n";
Ejemplo n.º 2
0
    }
    public function getCost()
    {
        return 15 + $this->carService->getCost();
    }
    public function getDesciption()
    {
        return $this->carService->getDesciption() . ' and  OilChange';
    }
}
class TireRotation implements CarService
{
    protected $carService;
    public function __construct(CarService $carService)
    {
        $this->carService = $carService;
    }
    public function getCost()
    {
        return 18 + $this->carService->getCost();
    }
    public function getDesciption()
    {
        return $this->carService->getDesciption() . ' and  TireRotation';
    }
}
$carService = new TireRotation(new OilChange(new BasicInspection()));
echo $carService->getDesciption();
echo '<br>';
echo $carService->getCost();
echo '<hr>';
Ejemplo n.º 3
0
        return 29 + $this->carService->getCost();
    }
    public function getDescription()
    {
        return $this->carService->getDescription() . ", and oil change";
    }
}
class TireRotation implements CarService
{
    /**
     * @var CarService
     */
    private $carService;
    function __construct(CarService $carService = null)
    {
        $this->carService = $carService;
    }
    public function getCost()
    {
        return 15 + $this->carService->getCost();
    }
    public function getDescription()
    {
        return $this->carService->getDescription() . ", and tire rotation";
    }
}
$service = new TireRotation(new OilChange(new BasicInspections()));
echo $service->getCost();
echo PHP_EOL;
echo $service->getDescription();
echo PHP_EOL;