/**
* 指令模式
*
* 將一個請求封裝為一個物件從而使你可用不同的請求對客戶進行參數化,對請求排除或記錄請求日誌,以及支援可取消的操作
*/
介面指令
{
public functionexecute();
}
類別呼叫者
{ private $ {
$this->_command[] = $command;
}
公共函數executeCommand()
{
foreach($this->_commandas $command) }
public function removeCommand($command)
{
$key = array_search($command, $this->_command);
if($key !== false)...
{
{ key]);
}
}
}
類接收者
{
private $_name = null;
類接收者
} {
) {
}$ function action()
{
echo $this->_name." action
";
}
e
public function action1()
{
e $this->_name." 1}
類ConcreteCommand 實作Command
{
private $_receiver;
公共函數__construct($receiver)
{
$this->_receiver = $reiveriver
}
$ this->_receiver->action();
}
}
類ConcreteCommand1 實作Command
{
private $_rece 我
公用函數execute()
{
$this->_receiver->action1();
}
}
類ConcreteCommand2 實作Command
}
類ConcreteCommand2 實作Command__repriate{prieprivate(
$this->_receiver = $receiver;
}
公用函數execute()
{
$this->_receiver->action();
$this->_receiver->action1();
$objRecevier = new Receiver("No.1");
$objRecevier1 = new Receiver("No.2");
$objRecevier2 = new Receiver("No.3");
$objRecevier2 = new Receiver("No.3"); $objRecevier);
$objCommand1 = new ConcreteCommand1($objRecevier);
$objCommand2 = new ConcreteCommand($objRecevier1);
$objCommand3 = new ConcreteCommand($objRecevier1);
$objCommand3 = new fobcrete 1($ob er2); //使用Recevier 的兩個方法
$objInvoker = new Invoker();
$objInvoker->setCommand($objCommand);
$objInvoker->setCommand($objCommand1);
$objInvoker->setCommand($objCommand1);
$objInvoker->setCommand($objCommand1);
$ker ->removeCommand($objCommand1);
$objInvoker->executeCommand();
$objInvoker->setCommand($objCommand2);
$objj遠;
$objInvoker->executeCommand();
[/代碼]