PHP结构型模式之外观模式(php常用设计模式和应用场景)不要告诉别人

随心笔谈2年前发布 admin
198 0 0
广告也精彩

<?php
// 子系统A
class SubSystemA
{
public function operationA()
{
echo “SubSystemA operation.\n”;
}
}
// 子系统B
class SubSystemB
{
public function operationB()
{
echo “SubSystemB operation.\n”;
}
}
// 子系统C
class SubSystemC
{
public function operationC()
{
echo “SubSystemC operation.\n”;
}
}
// 外观类
class Facade
{
private $subSystemA;
private $subSystemB;
private $subSystemC;
public function __construct()
{
$this->subSystemA=new SubSystemA();
$this->subSystemB=new SubSystemB();
$this->subSystemC=new SubSystemC();
}
public function operation()
{
$this->subSystemA->operationA();
$this->subSystemB->operationB();
$this->subSystemC->operationC();
}
}
// 客户端代码
$facade=new Facade();
$facade->operation();

© 版权声明

相关文章