receiver; public function __construct($receiver) { $this->_receiver = $receiver; }
public function execute() { $this->_receiver->action(); $this->_receiver->action1(); } }
$objRecevier = new Receiver("No.1"); $objRecevier1 = new Receiver("No.2"); $objRecevier2 = new Receiver("No.3");
$objCommand = new ConcreteCommand($objRecevier); $objCommand1 = new ConcreteCommand1($objRecevier); $objCommand2 = new ConcreteCommand($objRecevier1); $objCommand3 = new ConcreteCommand1($objRecevier1); $objCommand4 = new ConcreteCommand2($objRecevier2); // 使用 Recevier的两个方法
$objInvoker = new Invoker(); $objInvoker->setCommand($objCommand); $objInvoker->setCommand($objCommand1); $objInvoker->executeCommand(); $objInvoker->removeCommand($objCommand1); $objInvoker->executeCommand();