php 命令链模式,设计模式之------命令链模式
/***
**命令鏈模式:松散耦合為主題,發送消息,命令和請求通過一組命令
**封裝一系列操作
**?一條命令被看做只執行了一個函數
********/
Interface?ICommand{
function?isValue($val);
}
class?CommonClain{
private?$_command;
public?function?__construct(ICommand?$value){
$this->_command?=?$value;
}
public?function?execCommand($param){
foreach($param?as?$key?=>$val){
$this->_command->isValue($val);
}
}
}
class?doCommand?implements?ICommand{
public?function?isValue($val){
if($val){
echo?$val.'\n';
}
}
}
class?famCommand?implements?ICommand{
public?function?isValue($val){
if($val?!=?'famCommand'){
return?'famCommand';
}
}
}
$claim?=?new?CommonClain(new?doCommand());
echo?$claim->execCommand(array(1,22,33,44,55));
總結
以上是生活随笔為你收集整理的php 命令链模式,设计模式之------命令链模式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php常量变量连接,PHP常量及变量区别
- 下一篇: 摩尔庄园二级服装店怎么解锁