源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-02-04 05:39 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:php设计模式 Bridge (桥接模式)
[u]复制代码[/u] 代码如下:
<?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();
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部