php装饰器模式完成文章编辑

<?php
//文章父类
class BaseArt{
protected $content;
protected $art; 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;
$this->decorator();
}
public function decorator(){
return $this->content=$this->art->decorator().'文章摘要';
}
}
//SEO关键词
class SEOArt extends BaseArt{
public function __construct(BaseArt $art){
$this->art=$art;
$this->decorator();
}
public function decorator(){
return $this->content=$this->art->decorator().'SEO优化';
}
} $BA=new BaseArt('天天向上');
$b=new BianArt($BA);
echo $b->decorator();
$c=new SEOArt($b);
echo $c->decorator();
上一篇:Kubernetes - Getting Started With Kubeadm


下一篇:pthread 学习系列 case2-- pthread_mutex_t