php设计模式 Bridge (桥接模式)_php教程-查字典教程网
php设计模式 Bridge (桥接模式)
php设计模式 Bridge (桥接模式)
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:

复制代码 代码如下:

<?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教程学习
    编程开发子分类