手机
当前位置:查字典教程网 >编程开发 >php教程 >php设计模式 Bridge (桥接模式)
php设计模式 Bridge (桥接模式)
摘要:复制代码代码如下:

复制代码 代码如下:

<?php

/**

* 桥接模式

*

* 将抽象部份与它实现部分分离,使用它们都可以有独立的变化

*/

abstract class Implementor

{

abstract public function operation();

}

class ConcreteImplementorA extends Implementor

{

public function operation()

{

echo "ConcreteImplementorA Operation<br/>";

}

}

class ConcreteImplementorB extends Implementor

{

public function operation()

{

echo "ConcreteImplementorB Operation<br/>";

}

}

class Abstraction

{

protected $_implementor = null;

public function setImplementor($implementor)

{

$this->_implementor = $implementor;

}

public function operation()

{

$this->_implementor->operation();

}

}

class RefinedAbstraction extends Abstraction

{

}

class ExampleAbstraction extends Abstraction

{

}

//

$objRAbstraction = new RefinedAbstraction();

$objRAbstraction->setImplementor(new ConcreteImplementorB());

$objRAbstraction->operation();

$objRAbstraction->setImplementor(new ConcreteImplementorA());

$objRAbstraction->operation();

$objEAbstraction = new ExampleAbstraction();

$objEAbstraction->setImplementor(new ConcreteImplementorB());

$objEAbstraction->operation();

【php设计模式 Bridge (桥接模式)】相关文章:

类的另类用法--数据的封装

在线竞拍系统的PHP实现框架(一)

PHP脚本的10个技巧(4)

php计算到指定日期还有多少天的方法

PHP设计聊天室步步通

php基于curl扩展制作跨平台的restfule 接口

把从SQL中取出的数据转化成XMl格式

php实现插入排序

用 php 编写的日历

PHP设计模式之适配器模式代码实例

精品推荐
分类导航