PHP 外观模式

<?php
/**
 * 外观模式
 * 为其余子系统或者其余类.
 * 提供一个更高层的通用接口(或类).
 */

class TypeA  {
    public function getMy ()
    {
        echo 'TypeA'.PHP_EOL;
    }
}

class TypeB  {
    public function getMy ()
    {
        echo 'TypeB'.PHP_EOL;
    }
}

class TypeC  {
    public function getMy ()
    {
        echo 'TypeC'.PHP_EOL;
    }
}

/**
 * Class Exterior
 * 统一调用高级接口
 */
class Exterior {
    protected $typeA;
    protected $typeB;
    protected $typeC;

    public function __construct()
    {
        $this->typeA = new TypeA();
        $this->typeB = new TypeB();
        $this->typeC = new TypeC();
    }
    public function get ()
    {
        $this->typeA->getMy();
        $this->typeB->getMy();
        $this->typeC->getMy();
    }
}

$ext = new Exterior();
$ext->get();
//TypeA
//TypeB
//TypeC
相关文章
相关标签/搜索
本站公众号
   欢迎关注本站公众号,获取更多信息