大话设计模式-桥接模式

大话设计模式-桥接模式_第1张图片

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();



你可能感兴趣的:(大话设计模式-桥接模式)