<?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));
时间: 2024-10-13 16:03:45