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

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?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对象、模式与实践之高级特性分析

本文实例讲述了PHP面向对象程序设计高级特性。分享给大家供大家参考,具体如下: 高级特性 包括: 1.静态方法和属性(通过类而不是对象来访问数据和功能) 2.抽象类和接口(设计,实现分离...

PHP查询快递信息的方法

本文实例讲述了PHP查询快递信息的方法。分享给大家供大家参考。具体如下: 这里使用快递100物流查询 官方文档中只能返回html的接口 也可以返回json php代码如下: 复制代码 代...

php json中文编码为null的解决办法

今天使用json_encode函数,发现中文竟成了null。 原因分析:使用json_encode函数应应使用utf-8编码,我的页面用的是gbk. 解决:在json_encode函数前...

PHP中集成PayPal标准支付的实现方法分享

PHP中集成PayPal标准支付的实现方法分享

PayPal支付功能其实一直在更新文档和接口,这里说的是一个简单的支付功能大概流程如下 1,在网站的结账页面,设置一个提交到PayPal网站的form,里面有一些金额,商品名称,商家收款...

php删除页面记录 同时刷新页面 删除条件用GET方式获得

功能: 1、在某个页面上显示查询数据,并在每条数据后增加删除功能,点击“删除”,删除掉数据,同时刷新页面 2、用GET方式获得删除条件 数据库连接变量connectvars.php 复制...