桥接模式

桥接模式:将抽象部分与它的实现部分分离,使它们都可以独立的变化.

 

 

<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/2/28
* Time: 10:45
*/

namespace frontend\models;


abstract class Implementor
{

public abstract function Operation();

}




class ConcreteImplementorA  extends Implementor
{

public function Operation()
{
echo "实现方法A"."<br>";
}

}




<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/2/28
* Time: 10:47
*/

namespace frontend\models;


class ConcreteImplementorB extends Implementor
{

public function Operation()
{
echo "B类实现方法"."<br>";
}

}



<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/2/28
* Time: 10:48
*/

namespace frontend\models;


class Abstraction
{

private $implementor;

public function __construct($implementor)
{
$this->implementor = $implementor;
}

public function Operation(){

$this->implementor->Operation();

}
}





$abstraction = new Abstraction(new ConcreteImplementorA());

$abstraction->Operation();


$abstraction = new Abstraction(new ConcreteImplementorB());

$abstraction->Operation();


posted on 2018-02-28 10:53  paulversion  阅读(148)  评论(0编辑  收藏  举报