加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 05:55:40 所属栏目:PHP教程 来源:网络整理
导读:div class="codetitle" a style="CURSOR: pointer" data="69126" class="copybut" id="copybut69126" onclick="doCopy('code69126')" 代码如下: div class="codebody" id="code69126" ?php /* 桥接模式 将抽象部份与它实现部分分离,使用它们都可以有独立的变

<div class="codetitle"><a style="CURSOR: pointer" data="69126" class="copybut" id="copybut69126" onclick="doCopy('code69126')"> 代码如下:<div class="codebody" id="code69126">
<?php
/*
桥接模式

将抽象部份与它实现部分分离,使用它们都可以有独立的变化
*/
abstract class Implementor
{
abstract public function operation();
}
class ConcreteImplementorA extends Implementor
{
public function operation()
{
echo "ConcreteImplementorA Operation
";
}
}
class ConcreteImplementorB extends Implementor
{
public function operation()
{
echo "ConcreteImplementorB Operation
";
}
}
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();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读