设计模式-外观
作者:edwin
日期:2019-08-05 14:57:09
所属分类:后端 - php

统一的这种模式给一个子系统中的一套接口提供了一个统一的接口它定义了一个更高级别的接口使子系统更容易使用

SubsystemClass7
This class (a) implements subsystem functionality, (b) handles work assigned by the Facade object, and (c) keeps no reference to the facade.
(这类(a)实现子系统功能,(b)通过外观对象分配处理工作,并(c)。保持没有到外观的引用)

SubsystemClass6
This class (a) implements subsystem functionality, (b) handles work assigned by the Facade object, and (c) keeps no reference to the facade.
(这类(a)实现子系统功能,(b)通过外观对象分配处理工作,并(c)。保持没有到外观的引用)

SubsystemClass5
This class (a) implements subsystem functionality, (b) handles work assigned by the Facade object, and (c) keeps no reference to the facade.
(这类(a)实现子系统功能,(b)通过外观对象分配处理工作,并(c)。保持没有到外观的引用)

SubsystemClass4
This class (a) implements subsystem functionality, (b) handles work assigned by the Facade object, and (c) keeps no reference to the facade.
(这类(a)实现子系统功能,(b)通过外观对象分配处理工作,并(c)。保持没有到外观的引用)

SubsystemClass3
This class (a) implements subsystem functionality, (b) handles work assigned by the Facade object, and (c) keeps no reference to the facade.
(这类(a)实现子系统功能,(b)通过外观对象分配处理工作,并(c)。保持没有到外观的引用)

SubsystemClass2
This class (a) implements subsystem functionality, (b) handles work assigned by the Facade object, and (c) keeps no reference to the facade.
(这类(a)实现子系统功能,(b)通过外观对象分配处理工作,并(c)。保持没有到外观的引用)

SubsystemClass1
This class (a) implements subsystem functionality, (b) handles work assigned by the Facade object, and (c) keeps no reference to the facade.
(这类(a)实现子系统功能,(b)通过外观对象分配处理工作,并(c)。保持没有到外观的引用)

Facade(外观)
This class (a) knows which subsystem classes are responsible(负责的) for a request, and (b) delegates( ['dɛləgɪt] 代表) client requests to appropriate(适当的) subsystem objects.
(这类(a)知道哪个子系统的类负责哪一个请求,和(b)代表客户请求到适当子系统的对象上。)

代码实现

<?php

class SubSytem1
{
    public function Method1()
    {
        echo "subsystem1 method1";
    }
}


class SubSytem2
{
    public function Method2()
    {
        echo "subsystem2 method2";
    }
}


class SubSytem3
{
    public function Method3()
    {
        echo "subsystem3 method3";
    }
}

class Facade
{
    private $_object1 = null;
    private $_object2 = null;
    private $_object3 = null;

    public function __construct()
    {
        $this->_object1 = new SubSytem1();
        $this->_object2 = new SubSytem2();
        $this->_object3 = new SubSytem3();
    }

    public function MethodA()
    {
        echo "Facade MethodA";
        $this->_object1->Method1();
        $this->_object2->Method2();
    }

    public function MethodB()
    {
        echo "Facade MethodB";
        $this->_object2->Method2();
        $this->_object3->Method3();
    }
}

// 实例化
$objFacade = new Facade();

$objFacade->MethodA();
$objFacade->MethodB();

评论

全部评论 / 0