现在的位置: 首页 > 综合 > 正文

大话设计模式-桥接模式

2013年10月11日 ⁄ 综合 ⁄ 共 692字 ⁄ 字号 评论关闭

abstract class Implementor {
	public abstract function operation();
}

class ConcreteImplementorA extends Implementor {
	public function operation() {
		echo '具体实现A的方法执行<br/>';
	}
}

class ConcreteImplementorB extends Implementor {
	public function operation() {
		echo '具体实现B的方法执行<br/>';
	}
}

class Abstraction {
	protected $implementor;

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

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

}

class RefinedAbstraction extends Abstraction {
	public function operation() {
		$this->implementor->operation();
	}

}

$ab = new RefinedAbstraction();

$ab->setImplementor(new ConcreteImplementorA());
$ab->operation();

$ab->setImplementor(new ConcreteImplementorB());
$ab->operation();

抱歉!评论已关闭.