装饰器模式
<?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();