PHP100 2019-03-27
代码如下:
class car { public function start() { print_r("车子启动"); } public function check_stop() { print_r("刹车检查正常"); } public function check_box() { print_r("检查油箱正常"); } public function check_console() { print_r("检查仪表盘是否异常"); } } //facade模式 class carfacade { public function catgo(car $carref){ $carref->check_stop(); $carref->check_box(); $carref->check_console(); $carref->start(); } } //客户端可以简单的去调用。 $car = new car(); $carObj = new carfacade(); $carObj->catgo($car);
代码如下:
<?php /** * 外观模式 示例 * * 为子系统中的一组接口提供一个一致的界面,定义一个高层接口,使得这一子系统更加的容易使用 */ class SubSytem1 { public function Method1() { echo "subsystem1 method1<br/>"; } } class SubSytem2 { public function Method2() { echo "subsystem2 method2<br/>"; } } class SubSytem3 { public function Method3() { echo "subsystem3 method3<br/>"; } } class Facade { private $_object1 = null; private $_object2 = null; private $_object3 = null; public function __construct() { $this->_object1 = new SubSytem1(); $this->_object2 = new SubSytem2(); $this->_object3 = new SubSytem3(); } public function MethodA() { echo "Facade MethodA<br/>"; $this->_object1->Method1(); $this->_object2->Method2(); } public function MethodB() { echo "Facade MethodB<br/>"; $this->_object2->Method2(); $this->_object3->Method3(); } } // 实例化 $objFacade = new Facade(); $objFacade->MethodA(); $objFacade->MethodB();
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh