diff --git a/demo/Structural/Facade/BiosInterface.php b/demo/Structural/Facade/BiosInterface.php new file mode 100644 index 0000000..36be334 --- /dev/null +++ b/demo/Structural/Facade/BiosInterface.php @@ -0,0 +1,29 @@ +bios = $bios; + $this->os = $os; + } + + /** + * 构建基础输入输出系统执行启动方法。 + */ + public function turnOn() + { + $this->bios->execute(); + $this->bios->waitForKeyPress(); + $this->bios->launch($this->os); + } + + /** + * 构建系统关闭方法。 + */ + public function turnOff() + { + $this->os->halt(); + $this->bios->powerDown(); + } +} \ No newline at end of file diff --git a/demo/Structural/Facade/OsInterface.php b/demo/Structural/Facade/OsInterface.php new file mode 100644 index 0000000..b03c299 --- /dev/null +++ b/demo/Structural/Facade/OsInterface.php @@ -0,0 +1,19 @@ +createMock('DesignPatterns\Structural\Facade\OsInterface'); + + $os->method('getName') + ->will($this->returnValue('Linux')); + + $bios = $this->getMockBuilder('DesignPatterns\Structural\Facade\BiosInterface') + ->setMethods(['launch', 'execute', 'waitForKeyPress']) + ->disableAutoload() + ->getMock(); + + $bios->expects($this->once()) + ->method('launch') + ->with($os); + + $facade = new Facade($bios, $os); + + // 门面接口很简单。 + $facade->turnOn(); + + // 但你也可以访问底层组件。 + $this->assertEquals('Linux', $os->getName()); + } +} \ No newline at end of file