当前位置: 首页 > 后端技术 > PHP

装饰器模型

时间:2023-03-30 03:25:02 PHP

";}}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();

最新推荐
猜你喜欢