-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBridgePattern.php
More file actions
71 lines (63 loc) · 1.36 KB
/
Copy pathBridgePattern.php
File metadata and controls
71 lines (63 loc) · 1.36 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
<?php
/**
* This is bridge pattern of design pattern
*
* @author hkf <[email protected]>
* @version 0.1.0
*/
/**
* Class Abstraction
* 抽象化角色,抽象化给出的定义,并保存一个对实现化对象的引用
*/
abstract class Abstraction
{
protected $imp;
public function operationImp()
{
$this->imp->operationImp();
}
}
/**
* Class RefinedAbstraction
* 修正抽象化角色,扩展抽象化角色,改变和修正父类对抽象化的定义
*/
class RefinedAbstraction extends Abstraction
{
public function __construct(Implementor $imp)
{
$this->imp = $imp;
}
public function operation()
{
$this->imp->operationImp();
}
}
/**
* Class Implementor
* 实现化角色, 给出实现化角色的接口,但不给出具体的实现。
*/
abstract class Implementor
{
abstract public function operationImp();
}
/**
* Class ConcreteImplementorA
* 具体化角色A
*/
class ConcreteImplementorA extends Implementor
{
public function operationImp() {}
}
/**
* Class ConcreteImplementorB
* 具体化角色B
*/
class ConcreteImplementorB extends Implementor
{
public function operationImp() {}
}
// client
$abstraction = new RefinedAbstraction(new ConcreteImplementorA());
$abstraction->operation();
$abstraction = new RefinedAbstraction(new ConcreteImplementorB());
$abstraction->operation();