<?php
abstract class Human
{
abstract public function display();
}
class YellowHuman extends Human
{
public function display()
{
echo "YellowHuman";
}
}
class BlackHuman extends Human
{
public function display()
{
echo "BlackHuman";
}
}
abstract class HumanDecorator extends Human
{
protected $human;
public function __construct(Human $human)
{
$this->human = $human;
}
}
class WatchDecorator extends HumanDecorator
{
public function display()
{
echo $this->human->display()." with a Watch";
}
}
class GlassesDecorator extends HumanDecorator
{
public function display()
{
echo $this->human->display()." with a Glasses";
}
}
class Test
{
public function run()
{
$yellowHuman = new YellowHuman();
$blackHuman = new BlackHuman();
$yellowHumanWithWatch = new WatchDecorator($yellowHuman);
$blackHumanWithGlasses = new GlassesDecorator($blackHuman);
$yellowHumanWithWatchWithGlasses = new GlassesDecorator($yellowHumanWithWatch);
$yellowHuman->display();
echo "<br>\n";
$blackHuman->display();
echo "<br>\n";
$yellowHumanWithWatch->display();
echo "<br>\n";
$blackHumanWithGlasses->display();
echo "<br>\n";
$yellowHumanWithWatchWithGlasses->display();
}
}
$test = new Test();
$test->run();