Home >Backend Development >PHP Tutorial >PHP design pattern Bridge (bridge mode)_PHP tutorial

PHP design pattern Bridge (bridge mode)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:28:18847browse

复制代码 代码如下:

/**
* Bridge mode
*
* Separate the abstract part from its implementation part, and use them to make independent changes
*/
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();

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/323618.htmlTechArticle复制代码 代码如下: ?php /*** Bridge mode * * Separate the abstract part from its implementation part, and use them to make independent changes*/ abstract class Implementor { abstract publ...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn