";}}abstractclassDecoratorextendsComponent{protected$component;函数__construct(Component$component){$this->component=$component;}publicfunctionoperation(){$this->component->operation();}}classMyDecoratorextendsDecorator{function__construct(Component$component){parent::__construct($component);}publicfunctionaddMethod(){echo"这是装饰器添加的方法
";}publicfunctionoperation(){$this->addMethod();父母::操作();}}$component=newMyComponent();$da=newMyDecorator($component);$da->operation();
