裝飾器模式

<?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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章