@Chiang
2020-01-03T10:17:57.000000Z
字数 1409
阅读 1404
设计模式
- 外观对象
- 子系统
<?php
/**
* Facade
*
* @author Luffy <lufei@swoole.com>
* @date 2019/11/29
* @copyright Swoole, Inc.
* @package sy-records/design-patterns
*/
namespace Luffy\DesignPatterns\Facade;
class Facade
{
/**
* @var People
*/
private $people;
/**
* @var Package
*/
private $package;
/**
* Facade constructor.
*/
public function __construct()
{
$this->people = new People();
$this->package = new Package();
}
/**
* 寄快递
*/
public function send()
{
$this->people->say();
$this->package->pickup();
$this->package->inspection();
$this->package->bale();
$this->package->sendOut();
}
}
<?php
/**
* People
*
* @author Luffy <lufei@swoole.com>
* @date 2019/11/29
* @copyright Swoole, Inc.
* @package sy-records/design-patterns
*/
namespace Luffy\DesignPatterns\Facade;
class People
{
public function say()
{
echo "下单寄快递\n";
}
}
<?php
/**
* Package
*
* @author Luffy <lufei@swoole.com>
* @date 2019/11/29
* @copyright Swoole, Inc.
* @package sy-records/design-patterns
*/
namespace Luffy\DesignPatterns\Facade;
class Package
{
public function pickup()
{
echo "上门取件\n";
}
public function inspection()
{
echo "验视\n";
}
public function bale()
{
echo "打包\n";
}
public function sendOut()
{
echo "寄出\n";
}
}
<?php
/**
* Client
*
* @author Luffy <lufei@swoole.com>
* @date 2019/11/29
* @copyright Swoole, Inc.
* @package sy-records/design-patterns
*/
namespace Luffy\DesignPatterns\Facade;
include __DIR__ . '/../vendor/autoload.php';
class Client
{
public static function run()
{
$facade = new Facade();
$facade->send();
}
}
Client::run();