装饰器模式
发布时间:2020-12-14 04:45:51 所属栏目:大数据 来源:网络整理
导读:? php // 装饰器模式 class BaseArt { protected $content ; protected $art = null ; public function __construct( $content ){ $this -content = $content ; } public function decorator(){ return $this - content; }} // 编辑文章摘要 class BianArt e
<?php //装饰器模式 class BaseArt { protected $content; protected $art = null; public function __construct($content){ $this->content = $content; } public function decorator(){ return $this->content; } } //编辑文章摘要 class BianArt extends BaseArt { public function __construct(BaseArt $art){ $this->art = $art; } public function decorator(){ return $this->content = $this->art->decorator() . ‘,小编加上文章摘要‘; } } class SEOart extends BaseArt { public function __construct(BaseArt $art){ $this->art = $art; } public function decorator(){ return $this->content = $this->art->decorator() . ‘,SEO加上关键词‘; } } $b = new SEOart(new BianArt(new BaseArt(‘天天向上‘))); echo $b->decorator(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |