首页 > 其他 > 详细

设计模式之------命令链模式

时间:2015-02-12 02:03:18      阅读:213      评论:0      收藏:0      [点我收藏+]
<?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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!