<?php
#houdunwang.com 后盾人 人人做后盾
#houdunren.com
namespace app;
//定义装饰对象/装饰器规范的接口
interface Component
{
public function display();
}
//被装饰者
class Person implements Component
{
public function display()
{
echo '<br/>后盾网 www.houdunwang.com';
}
}
//抽象装饰器: 维护装饰链条的抽象类
abstract class Decorate implements Component
{
protected $componet;
public function __construct(Component $component)
{
$this->componet = $component;
}
public function display()
{
if ( ! is_null($this->componet)) {
$this->componet->display();
}
}
}
//装饰器: 用于装饰被装饰者
class Car extends Decorate
{
public function display()
{
echo "<br/>i have a car";
parent::display(); // TODO: Change the autogenerated stub
}
}
//装饰器
class Bus extends Decorate
{
public function display()
{
echo "<br/> I has a Bus";
parent::display();
}
}
$person = new Person();
$car = new Car($person);
$bus = new Bus($car);
$bus->display();
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。