标签:设计模式 命令链 模式
<?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));本文出自 “王尼美的成人之路” 博客,请务必保留此出处http://8335914.blog.51cto.com/8325914/1613811
标签:设计模式 命令链 模式
原文地址:http://8335914.blog.51cto.com/8325914/1613811