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(); 相关推荐
AscaryBird 2020-07-27
zcabcd 2020-04-30
summerinsist 2020-04-30
leeham 2020-04-19
Wytheme 2020-01-19
风吹草动 2019-12-18
水痕 2019-12-06
89284553 2019-12-04
xuebingnan 2019-10-23
87324554 2012-09-04
hce0 2015-12-05
小波波 2011-06-15
易分享 2015-05-06
wwwchinabignet 2011-07-08
麦田开拓者 2011-07-05
Palingenesis 2019-07-01
MoreWindowsBlog 2019-06-28
苗疆三刀的随手记 2019-06-28