-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathTemplate.php
More file actions
executable file
·142 lines (97 loc) · 2.61 KB
/
Template.php
File metadata and controls
executable file
·142 lines (97 loc) · 2.61 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Hummer Model 是悍马车辆模型的意思,不是悍马美女车模
*/
abstract class HummerModel {
/**
* 首先这个模型要被发动起来,别管是手动还是电动,
* 反正是要发动起来,那个实现要在实现类里
*/
protected abstract function start();
/**
* 能发动起,那还有能停才是本事
*/
protected abstract function stop();
/**
* 喇叭会出声是,滴滴叫,还是哗哗叫
*/
protected abstract function alarm();
/**
* 引擎会轰轰响的,不响那是假的
*/
protected abstract function enginBoom();
/**
* 那模型应该会跑吧,别管是人推,还是店里驱动,总之要会跑
*/
final public function run() {
//先发动汽车
$this->start();
//引擎开始轰鸣
$this->enginBoom();
//然后开始跑了,跑了一段时间遇到狗,按喇叭
if($this->isAlarm()) {
$this->alarm();
}
//到达目的地就停车
$this->stop();
}
/**
* 钩子方法,默认喇叭是会响的
*/
protected function isAlarm() {
return true;
}
}
/**
* 悍马车是每个越野者的最爱,其中H1系列最接近军用系列
*/
class HummerH1Model extends HummerModel {
private $alarmFlag = true; //是否要想喇叭
public function alarm() {
var_dump('悍马H1鸣笛...');
}
public function enginBoom() {
var_dump('悍马H1引擎声音是这样在...');
}
public function start() {
var_dump('悍马H1发动');
}
public function stop() {
var_dump('悍马H1停车');
}
protected function isAlarm() {
return $this->alarmFlag;
}
public function setAlarm($isAlarm) {
$this->alarmFlag = $isAlarm;
}
}
/**
* H1和H2有什么差别,还真不知道,没接触过悍马
*/
class HummerH2Model extends HummerModel {
public function alarm() {
var_dump('悍马H2鸣笛...');
}
public function enginBoom() {
var_dump('悍马H2引擎声音是这样在...');
}
public function start() {
var_dump('悍马H2发动');
}
public function stop() {
var_dump('悍马H2停车');
}
public function isAlarm() {
return false; //默认没有喇叭
}
}
/* 模型造好,客服开始使用 */
$h1 = new HummerH1Model();
$h1->run(); //汽车h1跑起来
$h2 = new HummerH2Model();
$h2->run(); //汽车h2跑起来
$hx1 = new HummerH1Model();
$hx1->setAlarm(true);
$hx1->run();
?>