php设计模式 Chain Of Responsibility (职责链模式)
2011-11-12 09:12
701 查看
简介:这是php设计模式 Chain Of Responsibility (职责链模式)的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。
class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=339157' scrolling='no'>
爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具
http://biancheng.dnbcw.info/php/339157.html pageNo:8
class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=339157' scrolling='no'>
1 <?php 2 /** 3 * 职责链模式 4 * 5 * 为解除请求的发送者和接收者之间的耦合,而使用多个对象都用机会处理这个请求,将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它 6 * 7 */ 8 abstract class Handler 9 { 10 protected $_handler = null; 11 12 public function setSuccessor($handler) 13 { 14 $this->_handler = $handler; 15 } 16 17 abstract function handleRequest($request); 18 } 19 20 class ConcreteHandlerZero extends Handler 21 { 22 public function handleRequest($request) 23 { 24 if($request == 0) 25 { 26 echo "0<br/>"; 27 } else { 28 $this->_handler->handleRequest($request); 29 } 30 } 31 } 32 33 class ConcreteHandlerOdd extends Handler 34 { 35 public function handleRequest($request) 36 { 37 if($request % 2) 38 { 39 echo $request." is odd<br/>"; 40 } else { 41 $this->_handler->handleRequest($request); 42 } 43 } 44 } 45 46 class ConcreteHandlerEven extends Handler 47 { 48 public function handleRequest($request) 49 { 50 if(!($request % 2)) 51 { 52 echo $request." is even<br/>"; 53 } else { 54 $this->_handler->handleRequest($request); 55 } 56 } 57 } 58 59 60 // 实例一下 61 $objZeroHander = new ConcreteHandlerZero(); 62 $objEvenHander = new ConcreteHandlerEven(); 63 $objOddHander = new ConcreteHandlerOdd(); 64 $objZeroHander->setSuccessor($objEvenHander); 65 $objEvenHander->setSuccessor($objOddHander); 66 67 foreach(array(2,3,4,5,0) as $row) 68 { 69 $objZeroHander->handleRequest($row); 70 }
爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具
http://biancheng.dnbcw.info/php/339157.html pageNo:8
相关文章推荐
- [php]php设计模式 Chain Of Responsibility (职责链模式)
- php设计模式 Chain Of Responsibility (职责链模式)
- 设计模式----Chain of Responsibility(职责链)模式
- C#设计模式——职责链模式(Chain Of Responsibility Pattern)
- 设计模式循序渐进(8)职责链模式 Chain Of Responsibility
- [设计模式学习笔记]CHAIN OF RESPONSIBILITY(职责链)
- 设计模式13 - 职责链Chain-Of-Responsibility
- 白话设计模式--实践应用--Chain of Responsibility(职责链)和factory模式
- 设计模式袖珍版 连续转载之 - Chain of Responsibility(职责链)
- JAVA设计模式十一:--Chain of Responsibility(职责链模式)
- JAVA设计模式十一--Chain of Responsibility(职责链模式)
- 设计模式笔记18:职责链模式(Chain of Responsibility Pattern)
- C#设计模式之二十职责链模式(Chain of Responsibility Pattern)【行为型】
- 设计模式笔记18:职责链模式(Chain of Responsibility Pattern)
- 设计模式 职责链模式(Chain of Responsibility Pattern)
- java设计模式之职责链模式 Chain of Responsibility
- C#设计模式——职责链模式(Chain Of Responsibility Pattern)
- 设计模式职责链模式(ChainofResponsibilityPattern)
- "围观"设计模式(22)--行为型之职责链模式(Chain Of Responsibility Pattern)