-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathfacade.php
67 lines (55 loc) · 1.41 KB
/
facade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Created by PhpStorm.
* User: lock
* Date: 2017/8/6
* Time: 00:33
* 外观模式(门面模式)
* 用于为子系统中的一组接口提供一个一致的界面。门面模式定义了一个高层接口,这个接口使得子系统更加容易使用。
* 引入门面角色之后,用户只需要直接与门面角色交互,用户与子系统之间的复杂关系由门面角色来实现,从而降低了系统的耦合度。
*/
class Os{
public function halt(){
echo 'I will halt'.PHP_EOL;
}
}
class Bios{
public function execute(){
echo 'execute code...'.PHP_EOL;
}
public function waitForKeyPress(){
echo 'waiting key press...'.PHP_EOL;
}
public function launch(){
echo 'launch process...'.PHP_EOL;
}
public function powerDown(){
echo 'shutdown system...'.PHP_EOL;
}
}
class Facade{
protected $os;
protected $bios;
public function __construct(Bios $bios,Os $os) {
$this->os = $os;
$this->bios = $bios;
}
/**
* turn on system
*/
public function turnOn(){
$this->bios->execute();
$this->bios->waitForKeyPress();
$this->bios->launch();
}
/**
* shutdown system
*/
public function turnOff(){
$this->os->halt();
$this->bios->powerDown();
}
}
$obj = new Facade(new Bios(),new Os());
$obj->turnOn();
$obj->turnOff();