您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
设计模式-文章编辑的难题
发布时间:2017-11-30 09:27:25编辑:雪饮阅读()
<?php
header('content-type:text/html;charset=utf-8');
class article{
protected $content;
public function __construct($content){
$this->content=$content;
}
public function decorator(){
return $this->content;
}
}
//小编加摘要
class BianArticle extends article{
public function summary(){
return $this->content;
}
}
//seo做description处理
class SEOArticle extends BianArticle{
public function seo(){
return $this->content;
}
}
//广告部为文章添加了广告
class ADArticle extends SEOArticle{
public function ad(){
return $this->content;
}
}
$art=new article('文章:郑州来了“陈一堂” 断痒有奇招(图)_网易新闻中心');
echo $art->decorator()."<br/>";
$art2=new BianArticle($art->decorator().' --摘要:郑州来了“陈一堂” 断痒有奇招(图),');
echo $art2->summary()."<br/>";
$art3=new ADArticle($art2->summary().' --广告:专注皮肤病外用产品12年,凭借其专注、专心、专业的水准屡创行业新高。');
echo $art3->ad();
/*
随着文章处理的环节越来越多,该类继承的就越深
*/
?>
关键字词:设计模式
上一篇:设计模式-说说多态
下一篇:设计模式-责任链模式完成举报功能