[php]php设计模式 Bridge (桥接模式)

1 <? php
2 /* *
3 * 桥接模式
4 *
5 * 将抽象部份与它实现部分分离,使用它们都可以有独立的变化
6 */
7 abstract class Implementor
8 {
9 abstract public function operation();
10 }
11
12 class ConcreteImplementorA extends Implementor
13 {
14 public function operation()
15 {
16 echo " ConcreteImplementorA Operation<br/> " ;
17 }
18 }
19
20 class ConcreteImplementorB extends Implementor
21 {
22 public function operation()
23 {
24 echo " ConcreteImplementorB Operation<br/> " ;
25 }
26 }
27
28 class Abstraction
29 {
30 protected $_implementor = null ;
31
32 public function setImplementor( $implementor )
33 {
34 $this -> _implementor = $implementor ;
35 }
36
37 public function operation()
38 {
39 $this -> _implementor -> operation();
40 }
41 }
42
43 class RefinedAbstraction extends Abstraction
44 {
45 }
46
47 class ExampleAbstraction extends Abstraction
48 {
49 }
50
51 //
52 $objRAbstraction = new RefinedAbstraction();
53 $objRAbstraction -> setImplementor( new ConcreteImplementorB());
54 $objRAbstraction -> operation();
55
56 $objRAbstraction -> setImplementor( new ConcreteImplementorA());
57 $objRAbstraction -> operation();
58
59 $objEAbstraction = new ExampleAbstraction();
60 $objEAbstraction -> setImplementor( new ConcreteImplementorB());
61 $objEAbstraction -> operation();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值