首页 > Web开发 > 详细

PHP设计模式之:装饰模式

时间:2014-03-15 02:03:15      阅读:524      评论:0      收藏:0      [点我收藏+]

<?php
// 人类
class Person
{
    private $name;
    public function __construct($name)
    {
        $this->name = $name;
    }

    public function Show()
    {
        echo "装扮" . $this->name;
    }
}

//服饰类
class Finery extends Person
{
    protected component;

    public function Decoration(Person $component)
    {
        $this->component = $component;
    }

    public function Show()
    {
        if($this->component != null)
        {
            $this->component->Show();
        }
    }
}

// 具体服饰类
class TShirts extends Finery
{
    public function Show()
    {
        echo "T 恤";
        $this->Show();
    }
}

class BigTrouser extends Finery
{
    public function Show()
    {
        echo "大裤";
        $this->Show();
    }
}

class Suit extends Finery
{
    public function Show()
    {
        echo "西装";
        $this->Show();
    }
}

$p = new Person("狗娘养的");

$bt = new BigTrouser();
$bt.Decoration($p);
$bt.Show();

bubuko.com,布布扣

PHP设计模式之:装饰模式,布布扣,bubuko.com

PHP设计模式之:装饰模式

原文:http://www.cnblogs.com/lin3615/p/3601327.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!