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

yipeiwu_com5年前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逐行读取txt文件写入数组的方法 原创

本文实例讲述了php逐行读取txt文件写入数组的方法。分享给大家供大家参考。具体如下: 假设有user.txt文件如下: user01 user02 user03 user04 us...

PHP通过get方法获得form表单数据方法总结

PHP通过get方法获得form表单数据方法总结

我们在进行网页交互设计的时候,通常都会使用PHP中get变量方法来获得form表单中的数据,以此来实现各种网页动态查询或者请求。对于稍有HTML基础的朋友来说,应该都知道HTML for...

phpinfo()中Loaded Configuration File(none)的解决方法

phpinfo()中Loaded Configuration File(none)的解决方法

前言 单独编译php7,并安装在/usr/local/php7/中,今天开发插件修改了 php.ini 的配置信息,但是什么都没生效。 排查 通过phpinfo()查看配置信息:...

php实现验证邮箱格式的代码实例

验证邮箱格式是否正确可以通过filter_var函数来实现。函数介绍:filter_var() 函数通过指定的过滤器过滤一个变量。语法: filter_var(variable, ...

PHP Header用于页面跳转要注意的几个问题总结

1.header()函数 header()函数是PHP中进行页面跳转的一种十分简单的方法。header()函数的主要功能是将HTTP协议标头(header)输出到浏览器。 header(...