标签:struct new client 关心 封装 客户 main cad func
门面模式核心内容:
先定义两个子系统,子系统有各自的操作方法:
class SystemA
{
public function operationA()
{
//
}
}
class SystemB
{
public function operationB()
{
//
}
}
定义一个外观类,提供单一入口,内部负责调用子系统的方法:
class Facade
{
private $systemA;
private $systemB;
public function __construct()
{
$this->systemA = new SystemA;
$this->systemB = new SystemB;
}
public function operation()
{
$this->systemA->operationA();
$this->systemB->operationB();
}
}
定义客户端,客户端只需要与外观类交互即可实现对子系统的调用:
class Client
{
public function main()
{
(new Facade)->operation();
}
}
标签:struct new client 关心 封装 客户 main cad func
原文地址:https://www.cnblogs.com/danhuang/p/13165152.html