为子系统种的一组接口提供一个一致的界面,用来访问子系统种的一群接口 又称为门面模式<br />子接口太多,操作类里面一大堆,将一大堆接口封装一下,外部统一调用封装后的接口,<br />比如说,去医院看病,挂号,门诊,化验,取药,好几个地方,需要病人每个都接触一遍,外观模式就是,增加一个接待员,病人直接找接待员就好,接待员负责接触其他科室,![image.png](https://cdn.nlark.com/yuque/0/2021/png/22438777/1635242127836-170a3bb5-98d7-452f-8082-ffe3dce6fea3.png#clientId=u3c0b05b6-70e0-4&from=paste&height=463&id=ud535302d&margin=%5Bobject%20Object%5D&name=image.png&originHeight=463&originWidth=655&originalType=binary&ratio=1&size=70474&status=done&style=none&taskId=uf9512413-db26-4a59-a266-9b70a707143&width=655)
<?php
class SubSystemOne
{
public function MethodOne()
{
echo '子系统方法一';
}
}
class SubSystemTwo
{
public function MethodTwo()
{
echo '子系统方法二';
}
}
class SubSystemThree
{
public function MethodThree()
{
echo '子系统方法三';
}
}
class SubSystemFour
{
public function MethodFour()
{
echo '子系统方法四';
}
}
//外观类
class Facade
{
public $SubSystemOne;
public $SubSystemTwo;
public $SubSystemThree;
public $SubSystemFour;
public function __construct()
{
$this->SubSystemOne = new SubSystemOne();
$this->SubSystemTwo = new SubSystemTwo();
$this->SubSystemThree = new SubSystemThree();
$this->SubSystemFour = new SubSystemFour();
}
public function MethodA()
{
echo '系统A';
$this->SubSystemOne->MethodOne();
$this->SubSystemTwo->MethodTwo();
}
public function MethodB()
{
echo '系统B';
$this->SubSystemThree->MethodThree();
$this->SubSystemFour->MethodFour();
}
}
/**
* 操作类
*/
class ClassName
{
public function main()
{
$Facade = new Facade();
$Facade->MethodA();
$Facade->MethodB();
}
}
$name= new ClassName();
$name->main();