<?php
interface CoffeeService {
public function getCost();
public function getDescription();
}
class SingleCoffee implements CoffeeService{
public function getCost(){
return 15;
}
public function getDescription(){
return 'Single Coffee';
}
}
class Milk implements CoffeeService {
protected $coffeeService;
function __construct(CoffeeService $coffeeService){
$this->coffeeService = $coffeeService;
}
public function getCost(){
return 5 + $this->coffeeService->getCost();
}
public function getDescription(){
return $this->coffeeService->getDescription() . ', with milk';
}
}
class Cinnamon implements CoffeeService {
protected $coffeeService;
function __construct(CoffeeService $coffeeService){
$this->coffeeService = $coffeeService;
}
public function getCost(){
return 2 + $this->coffeeService->getCost();
}
public function getDescription(){
return $this->coffeeService->getDescription() . ', with cinammon';
}
}
$coffeeService = new Cinnamon(new Milk(new SingleCoffee));
echo $coffeeService->getCost();
echo $coffeeService->getDescription();