装饰器模式

<?php
class BaseArticle
{
	protected $content;
	protected $article = null;
	
	public function __construct($content)
	{
		$this->content = $content;
	}
	public function decorator(){
		return $this->content;
	}
}
# 装饰
class SeoArticle extends BaseArticle
{
	public function __construct(BaseArticle $article){
		$this->article = $article;
		$this->decorator();
	}
	public function decorator(){
		return $this->content = $this->article->decorator() . 'SEO关键词';
	}
}

$base = new SeoArticle(new BaseArticle('好好学习'));
echo $base->decorator();

 

发布了224 篇原创文章 · 获赞 19 · 访问量 6万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章