<?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();