笔记8:装饰器模式

<?php

class BaseArticle
{

    protected $content;

    protected $art = null;

    public function __construct($content)
    {
        $this->content = $content;
    }

    public function decorator()
    {
        return $this->content;
    }
}

// 小编加摘要
class BianArticle extends BaseArticle
{

    public function __construct(BaseArticle $art)
    {
        $this->art = $art;
        $this->decorator();
    }

    public function decorator()
    {
        return $this->content = $this->art->decorator() . ' 小编摘要';
    }
}


// SEO
class SEOArticle extends BaseArticle
{

    public function __construct(BaseArticle $art)
    {
        $this->art = $art;
        $this->decorator();
    }

    public function decorator()
    {
        return $this->content = $this->art->decorator() . ' SEO';
    }
}


$b = new SEOArticle(new BianArticle(new BaseArticle("好好学习")));
echo $b->decorator();