门面模式是指提供一个统一的接口来调用多个子系统的接口;这个名称的人关注的是由多个接口不统一的子系统对外提供统一的接口,好像形成了一个界面或者门面一样,所以叫门面模式吧
/**
* Author: shanhuhai
* Date: 2017/9/2 21:46
* Mail: 441358019@qq.com
*/
/**
* 订单系统
* Class Order
*/
class Order {
public function run() {
echo "下单".PHP_EOL;
}
}
/**
* 购物车系统
* Class Cart
*/
class Cart {
protected $goods = [];
public function add($good) {
echo "购物车中添加了".$good.PHP_EOL;
array_push($this->goods, $good);
}
}
/**
* 支付系统
* Class Pay
*/
class Pay{
public function run() {
echo "支付订单".PHP_EOL;
}
}
/**
* 用户界面
* Class UserUI
*/
class UserUI {
protected $cart;
protected $order ;
protected $pay;
public function __construct() {
$this->cart = new Cart();
$this->order = new Order();
$this->pay = new Pay();
}
/**
* 选择商品
*/
public function buy() {
$this->cart->add('iphone');
$this->cart->add('iPad');
$this->order->run();
$this->pay->run();
}
}
$userui = new UserUI();
$userui->buy();