zoukankan      html  css  js  c++  java
  • PHP设计模式之:装饰模式

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

  • 相关阅读:
    flask_admin+flask_login 整合,jieba分词+echarts数据分析可视化
    古诗词网爬虫实现
    Flask admin Flask login 整合模板
    API网关Kong
    Flask添加新命令
    MyBatis连接MySQL8配置
    golang锁
    golang goroutine
    golang管道
    golang结构体
  • 原文地址:https://www.cnblogs.com/lin3615/p/3601327.html
Copyright © 2011-2022 走看看