public static function main() { $abstraction = new RefinedAbstraction(new ConcreteImplementorA()); $abstraction->operate(); $abstraction = new RefinedAbstraction(new ConcreteImplementorB()); $abstraction->operate(); }
{ echo "ConcreteImplementorB Operation<br/>"; } } 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();