什么是php Bridge (桥接模式)

来源:爱站网时间:2021-08-04编辑:网友分享
最近有小伙伴来问小编说还不太清楚php Bridge (桥接模式),这个可难不倒爱站小编,马上准备了一篇有详细介绍了关于php Bridge (桥接模式)相关资料内容,内容很全面,大家可以马克起来!
复制代码 代码如下:

/**
* 桥接模式
*
* 将抽象部份与它实现部分分离,使用它们都可以有独立的变化
*/
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();大家应该

 以上内容就是爱站技术频道小编为大家解答的什么是php Bridge (桥接模式),看完以上分享之后,大家知道什么是什么是php Bridge (桥接模式)了吧,还不赶快马克起来吗。

上一篇:PHP中date函数有几个参数

下一篇:URL跳转代码有哪些

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载