﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-老范记事</title><link>http://www.cnitblog.com/fanyh/</link><description>If you think you can, you can!</description><language>zh-cn</language><lastBuildDate>Wed, 29 Apr 2026 05:58:56 GMT</lastBuildDate><pubDate>Wed, 29 Apr 2026 05:58:56 GMT</pubDate><ttl>60</ttl><item><title>Observer模式</title><link>http://www.cnitblog.com/fanyh/archive/2010/06/14/66752.html</link><dc:creator>fanyh</dc:creator><author>fanyh</author><pubDate>Mon, 14 Jun 2010 15:54:00 GMT</pubDate><guid>http://www.cnitblog.com/fanyh/archive/2010/06/14/66752.html</guid><wfw:comment>http://www.cnitblog.com/fanyh/comments/66752.html</wfw:comment><comments>http://www.cnitblog.com/fanyh/archive/2010/06/14/66752.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/fanyh/comments/commentRss/66752.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/fanyh/services/trackbacks/66752.html</trackback:ping><description><![CDATA[<p>UML图<br><img border=0 src="http://www.cnitblog.com/images/cnitblog_com/fanyh/Observer_class_diagram.png" width=819 height=604><br><br>代码：<br>&lt;?php<br>class Customer{<br>&nbsp;private $id ;<br>&nbsp;private $name ;<br>&nbsp;private $address ;<br>&nbsp;private $tel ;<br>&nbsp;private static $observers = array() ;<br>&nbsp;/**<br>&nbsp; * @return the $id<br>&nbsp; */<br>&nbsp;public function getId() {<br>&nbsp;&nbsp;return $this-&gt;id;<br>&nbsp;}</p>
<p>&nbsp;/**<br>&nbsp; * @return the $name<br>&nbsp; */<br>&nbsp;public function getName() {<br>&nbsp;&nbsp;return $this-&gt;name;<br>&nbsp;}</p>
<p>&nbsp;/**<br>&nbsp; * @return the $address<br>&nbsp; */<br>&nbsp;public function getAddress() {<br>&nbsp;&nbsp;return $this-&gt;address;<br>&nbsp;}</p>
<p>&nbsp;/**<br>&nbsp; * @return the $tel<br>&nbsp; */<br>&nbsp;public function getTel() {<br>&nbsp;&nbsp;return $this-&gt;tel;<br>&nbsp;}</p>
<p>&nbsp;/**<br>&nbsp; * @param $id the $id to set<br>&nbsp; */<br>&nbsp;public function setId($id) {<br>&nbsp;&nbsp;$this-&gt;id = $id;<br>&nbsp;}</p>
<p>&nbsp;/**<br>&nbsp; * @param $name the $name to set<br>&nbsp; */<br>&nbsp;public function setName($name) {<br>&nbsp;&nbsp;$this-&gt;name = $name;<br>&nbsp;}</p>
<p>&nbsp;/**<br>&nbsp; * @param $address the $address to set<br>&nbsp; */<br>&nbsp;public function setAddress($address) {<br>&nbsp;&nbsp;$this-&gt;address = $address;<br>&nbsp;}</p>
<p>&nbsp;/**<br>&nbsp; * @param $tel the $tel to set<br>&nbsp; */<br>&nbsp;public function setTel($tel) {<br>&nbsp;&nbsp;$this-&gt;tel = $tel;<br>&nbsp;}<br>&nbsp;/**<br>&nbsp; * <br>&nbsp; * @param Observer $observer<br>&nbsp; */<br>&nbsp;public static function attach($observer){<br>&nbsp;&nbsp;if (!in_array($observer , self::$observers)){<br>&nbsp;&nbsp;&nbsp;self::$observers[] = $observer ;<br>&nbsp;&nbsp;}<br>&nbsp;}<br>&nbsp;/**<br>&nbsp; * <br>&nbsp; * @param Observer $observer<br>&nbsp; */<br>&nbsp;public static function detach($observer){<br>&nbsp;&nbsp;foreach (self::$observers as $k =&gt; $item) {<br>&nbsp;&nbsp;&nbsp;if ($item == $observer){<br>&nbsp;&nbsp;&nbsp;&nbsp;unset(self::$observers[$k]) ;<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;}<br>&nbsp;}<br>&nbsp;/**<br>&nbsp; * 通知所有的观察者<br>&nbsp; */<br>&nbsp;public function notify(){<br>&nbsp;&nbsp;foreach (self::$observers as $observer) {<br>&nbsp;&nbsp;&nbsp;$observer-&gt;update($this) ;<br>&nbsp;&nbsp;}<br>&nbsp;}<br>}<br>interface Observer{<br>&nbsp;/**<br>&nbsp; * <br>&nbsp; * @param Customer $customer<br>&nbsp; */<br>&nbsp;public function update($customer) ;<br>&nbsp;<br>}</p>
<p>class Address implements Observer{<br>&nbsp;private $address = 'tianhe' ;<br>&nbsp;/**<br>&nbsp; * <br>&nbsp; * @param Customer $customer<br>&nbsp; */<br>&nbsp;public function update($customer){<br>&nbsp;&nbsp;if ($customer-&gt;getAddress() != $this-&gt;address){<br>&nbsp;&nbsp;&nbsp;echo '地址变了...................' ;<br>&nbsp;&nbsp;&nbsp;echo '&lt;br&gt;' ;<br>&nbsp;&nbsp;}<br>&nbsp;}<br>}</p>
<p>class Tel implements Observer{<br>&nbsp;private $tel = 13602413192 ;<br>&nbsp;/**<br>&nbsp; * <br>&nbsp; * @param Customer $customer<br>&nbsp; */<br>&nbsp;public function update($customer){<br>&nbsp;&nbsp;if ($customer-&gt;getTel() != $this-&gt;tel){<br>&nbsp;&nbsp;&nbsp;echo '电话变了...............' ;<br>&nbsp;&nbsp;&nbsp;echo '&lt;br&gt;' ;<br>&nbsp;&nbsp;}<br>&nbsp;}<br>}<br>header("Content-Type:text/html;charset=utf-8") ;<br>$address = new Address() ;<br>$tel = new Tel() ;<br>Customer::attach($address) ;<br>Customer::attach($tel) ;</p>
<p>$customer = new Customer() ;<br>$customer-&gt;notify() ;</p>
<p>?&gt;<br><br>本模式特性:<br>1.被观察者不需要知道自己被那些对象(观察者)观察着,观察者知道自己要观察谁(调用被观察者的attach()方法)<br>2.被观察者只需要在属性发生改变时,调用notify()方法,则所有在观察自己的对象都知道做出何种反应(观察者通过update()来做出反应) </p>
<img src ="http://www.cnitblog.com/fanyh/aggbug/66752.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/fanyh/" target="_blank">fanyh</a> 2010-06-14 23:54 <a href="http://www.cnitblog.com/fanyh/archive/2010/06/14/66752.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何看掌纹？</title><link>http://www.cnitblog.com/fanyh/archive/2010/04/18/65395.html</link><dc:creator>fanyh</dc:creator><author>fanyh</author><pubDate>Sun, 18 Apr 2010 13:35:00 GMT</pubDate><guid>http://www.cnitblog.com/fanyh/archive/2010/04/18/65395.html</guid><wfw:comment>http://www.cnitblog.com/fanyh/comments/65395.html</wfw:comment><comments>http://www.cnitblog.com/fanyh/archive/2010/04/18/65395.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/fanyh/comments/commentRss/65395.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/fanyh/services/trackbacks/65395.html</trackback:ping><description><![CDATA[<span style="LINE-HEIGHT: 1.8em">男左女右 </span><wbr><br><br><span style="LINE-HEIGHT: 1.8em">1)生命线： </span><wbr><br><span style="LINE-HEIGHT: 1.8em">生命纹--从大拇指与食指中间的掌边开始,往掌底走的纹路. </span><wbr><br><span style="LINE-HEIGHT: 1.8em">生命纹的长短并不代表寿命的长短,而是代表生命力的强弱,所以生命纹其实应该教做生命力纹. </span><wbr><br><span style="LINE-HEIGHT: 1.8em">生命纹长.深.红润-----生命力强,对疾病的抵抗力强,不容易生病;相反的,如果纹浅.弱,就比较衰弱. </span><wbr><br><span style="LINE-HEIGHT: 1.8em">纹粗---适合劳动或运动,纹细的适合用脑 </span><wbr><br><span style="LINE-HEIGHT: 1.8em">生命纹包围的掌丘范围大的,也是精力充沛,爱欲旺盛;范围小的嬴弱,容易疲倦 </span><wbr><br><span style="LINE-HEIGHT: 1.8em">生命纹开头(靠掌边)有链形纹的,儿童时期体弱多病 </span><wbr><br><span style="LINE-HEIGHT: 1.8em">生命纹尾端有如流苏,要防老人病 </span><wbr><br><span style="LINE-HEIGHT: 1.8em">生命纹上有岛纹,代表某一时间生病或住院,岛纹大小代表病情的轻重与时间长短</span><wbr><br><a href="http://pop.pcpop.com/upimg3/2005/10/26/0000133878.gif" target=_blank eventsListUID="e3"><span style="LINE-HEIGHT: 1.8em; FONT-SIZE: 18px"><wbr><a href="http://pop.pcpop.com/upimg3/2005/10/26/0000133878.gif" target=_blank eventsListUID="e4"><img style="BORDER-RIGHT-WIDTH: 0px; WIDTH: 550px; BACKGROUND: none transparent scroll repeat 0% 0%; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; HEIGHT: 503px; BORDER-LEFT-WIDTH: 0px" src="http://pop.pcpop.com/upimg3/2005/10/26/0000133878.gif" eventsListUID="e39" quoteTimer="86453062" errorLoaded="true" orgSrc="http://pop.pcpop.com/upimg3/2005/10/26/0000133878.gif"></a><wbr></span><wbr></a><wbr><br><br><a href="http://pop.pcpop.com/upimg3/2005/10/26/0000133888.jpg" target=_blank eventsListUID="e5"><span style="LINE-HEIGHT: 1.8em; FONT-SIZE: 18px"><wbr><a href="http://pop.pcpop.com/upimg3/2005/10/26/0000133888.jpg" target=_blank eventsListUID="e6"><img style="BORDER-RIGHT-WIDTH: 0px; WIDTH: 550px; BACKGROUND: none transparent scroll repeat 0% 0%; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; HEIGHT: 503px; BORDER-LEFT-WIDTH: 0px" src="http://pop.pcpop.com/upimg3/2005/10/26/0000133888.jpg" eventsListUID="e40" errorLoaded="true" orgSrc="http://pop.pcpop.com/upimg3/2005/10/26/0000133888.jpg"></a><wbr></span><wbr></a><wbr><span style="LINE-HEIGHT: 1.8em">2）智能线 </span><wbr><br><br><span style="LINE-HEIGHT: 1.8em">智能线至又称脑纹是掌相中最重要的一纹,中国手相中此纹代表自己,又称人纹.起点与生命线同,向小指方向走,至无名指与小指指缝间停最好,太短不够聪明,太长则精明过度,亦不好. </span><wbr><br><span style="LINE-HEIGHT: 1.8em">脑纹以深细为佳,表示思想能够集中,头脑聪明. </span><wbr><br><span style="LINE-HEIGHT: 1.8em">脑纹上有岛纹就表示思想不集中,记意力弱或脑部受挫. </span><wbr><br><span style="LINE-HEIGHT: 1.8em">脑纹起点有链行外在环境影响求学智能纹与生命纹起点一起, 两纹合为一,一段距离后才分开,表示内向,谨慎,考虑周详, </span><wbr><br><span style="LINE-HEIGHT: 1.8em">连的太长,则多虑,容易游豫不决. </span><wbr><br><span style="LINE-HEIGHT: 1.8em">如果生命线和智能线起点一起随后马上分开走,个性果断,能随机应变 </span><wbr><br><span style="LINE-HEIGHT: 1.8em">如果两线分开有距离,是大胆外向的个性,天不怕地不怕. </span><wbr><br><span style="LINE-HEIGHT: 1.8em">如果两线起点分开超过半公分以上,就成莽撞不经大脑的个性了</span><wbr><br><a href="http://pop.pcpop.com/upimg3/2005/10/26/0000133914.jpg" target=_blank eventsListUID="e7"><span style="LINE-HEIGHT: 1.8em; FONT-SIZE: 18px"><wbr><a href="http://pop.pcpop.com/upimg3/2005/10/26/0000133914.jpg" target=_blank eventsListUID="e8"><img style="BORDER-RIGHT-WIDTH: 0px; WIDTH: 550px; BACKGROUND: none transparent scroll repeat 0% 0%; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; HEIGHT: 503px; BORDER-LEFT-WIDTH: 0px" src="http://pop.pcpop.com/upimg3/2005/10/26/0000133914.jpg" eventsListUID="e41" quoteTimer="86453110" errorLoaded="true" orgSrc="http://pop.pcpop.com/upimg3/2005/10/26/0000133914.jpg"></a><wbr></span><wbr></a><wbr><br><br><a href="http://pop.pcpop.com/upimg3/2005/10/26/0000134029.jpg" target=_blank eventsListUID="e9"><span style="LINE-HEIGHT: 1.8em; FONT-SIZE: 18px"><wbr><a href="http://pop.pcpop.com/upimg3/2005/10/26/0000134029.jpg" target=_blank eventsListUID="e10"><img style="BORDER-RIGHT-WIDTH: 0px; WIDTH: 550px; BACKGROUND: none transparent scroll repeat 0% 0%; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; HEIGHT: 503px; BORDER-LEFT-WIDTH: 0px" src="http://pop.pcpop.com/upimg3/2005/10/26/0000134029.jpg" eventsListUID="e42" errorLoaded="true" orgSrc="http://pop.pcpop.com/upimg3/2005/10/26/0000134029.jpg"></a><wbr></span><wbr></a><wbr><br><span style="LINE-HEIGHT: 1.8em">3）感情线 </span><wbr><br><br><span style="LINE-HEIGHT: 1.8em">感情纹又名天纹或父纹,从小指下掌边起向食指方向走,以走入食指与中指缝为中庸, </span><wbr><br><span style="LINE-HEIGHT: 1.8em">若一直前进至食指下,属于心灵之域,较注重精神的爱;进入中指下面,属肉体之爱,并不注重海誓山盟 </span><wbr><br><span style="LINE-HEIGHT: 1.8em">如果在中指下往下弯,就爱得任性,不哲手段 </span><wbr><br><span style="LINE-HEIGHT: 1.8em">若感情线长而且有分岔往下弯,则是舍一切为情牺牲 </span><wbr><br><span style="LINE-HEIGHT: 1.8em">感情线深细的,感情也细腻,感情线粗浅的,感情也粗放; </span><wbr><br><span style="LINE-HEIGHT: 1.8em">感情线头端(掌边)如果上下都有像羽毛状的斜纹,表是这人很热情 </span><wbr><br><span style="LINE-HEIGHT: 1.8em">若线下没羽毛纹,只有线上有,那是机智线,表示反应好能随机应变 </span><wbr><br><span style="LINE-HEIGHT: 1.8em">感情纹如果是链行,多愁善感. </span><wbr><br><span style="LINE-HEIGHT: 1.8em">感情纹有岛形纹,如出现在无名指下,代表眼睛有问题,近视弱视或闪光. </span><wbr><br><span style="LINE-HEIGHT: 1.8em">若岛纹出现在其它位置,是感情上的困扰 </span><wbr><br><span style="LINE-HEIGHT: 1.8em">感情线断裂,象征感情受到很大的挫折 </span><wbr><br><br><a href="http://pop.pcpop.com/upimg3/2005/10/26/0000134204.jpg" target=_blank eventsListUID="e11"><span style="LINE-HEIGHT: 1.8em; FONT-SIZE: 13px"><wbr><a href="http://pop.pcpop.com/upimg3/2005/10/26/0000134204.jpg" target=_blank eventsListUID="e12"><img style="BORDER-RIGHT-WIDTH: 0px; WIDTH: 550px; BACKGROUND: none transparent scroll repeat 0% 0%; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; HEIGHT: 502px; BORDER-LEFT-WIDTH: 0px" src="http://pop.pcpop.com/upimg3/2005/10/26/0000134204.jpg" eventsListUID="e43" quoteTimer="86453261" errorLoaded="true" orgSrc="http://pop.pcpop.com/upimg3/2005/10/26/0000134204.jpg"></a></span>
<img src ="http://www.cnitblog.com/fanyh/aggbug/65395.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/fanyh/" target="_blank">fanyh</a> 2010-04-18 21:35 <a href="http://www.cnitblog.com/fanyh/archive/2010/04/18/65395.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP中的拦截器设计</title><link>http://www.cnitblog.com/fanyh/archive/2010/03/18/64720.html</link><dc:creator>fanyh</dc:creator><author>fanyh</author><pubDate>Thu, 18 Mar 2010 13:08:00 GMT</pubDate><guid>http://www.cnitblog.com/fanyh/archive/2010/03/18/64720.html</guid><wfw:comment>http://www.cnitblog.com/fanyh/comments/64720.html</wfw:comment><comments>http://www.cnitblog.com/fanyh/archive/2010/03/18/64720.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnitblog.com/fanyh/comments/commentRss/64720.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/fanyh/services/trackbacks/64720.html</trackback:ping><description><![CDATA[<p>&lt;?php<br>class Action{</p>
<p>&nbsp;public function perform(){<br>&nbsp;&nbsp;echo 'hello,fanyh!&lt;br&gt;' ;<br>&nbsp;}<br>}<br>/**<br>&nbsp;* Interceptor接口<br>&nbsp;* @author Administrator<br>&nbsp;*<br>&nbsp;*/<br>interface Interceptor{<br>&nbsp;/**<br>&nbsp; * 在指定的方法之前执行<br>&nbsp; */<br>&nbsp;public function doBefore() ;<br>&nbsp;/**<br>&nbsp; * 在指定的方法之后 执行<br>&nbsp; */<br>&nbsp;public function doAfter() ;<br>}<br>/**<br>&nbsp;* 所有Interceptor的基类<br>&nbsp;* @author Administrator<br>&nbsp;*<br>&nbsp;*/<br>abstract class AbstractInterceptor implements Interceptor{</p>
<p>&nbsp;public final function invoke($object,$method,$args=null){<br>&nbsp;&nbsp;$this-&gt;doBefore() ;<br>&nbsp;&nbsp;if(method_exists($object,$method)){<br>&nbsp;&nbsp;&nbsp;$object-&gt;$method($args);<br>&nbsp;&nbsp;}<br>&nbsp;&nbsp;$this-&gt;doAfter() ;<br>&nbsp;}<br>}</p>
<p>/**<br>&nbsp;* 定义一个Interceptor<br>&nbsp;* @author Administrator<br>&nbsp;*<br>&nbsp;*/<br>class InterceptorImpl1 extends AbstractInterceptor{<br>&nbsp;/**<br>&nbsp; * <br>&nbsp; */<br>&nbsp;public function doBefore() {<br>&nbsp;&nbsp;echo 'Before method......111111111111111111&lt;br&gt;' ;<br>&nbsp;}</p>
<p>&nbsp;/**<br>&nbsp; * <br>&nbsp; */<br>&nbsp;public function doAfter() {<br>&nbsp;&nbsp;echo 'After method......1111111111111111111&lt;br&gt;' ;<br>&nbsp;}<br>}<br>/**<br>&nbsp;* 定义一个Interceptor<br>&nbsp;* @author Administrator<br>&nbsp;*<br>&nbsp;*/<br>class InterceptorImpl2 extends AbstractInterceptor{<br>&nbsp;/**<br>&nbsp; * <br>&nbsp; */<br>&nbsp;public function doBefore() {<br>&nbsp;&nbsp;echo 'Before method......2222222222222&lt;br&gt;' ;<br>&nbsp;}</p>
<p>&nbsp;/**<br>&nbsp; * <br>&nbsp; */<br>&nbsp;public function doAfter() {<br>&nbsp;&nbsp;echo 'After method......22222222222222222&lt;br&gt;' ;<br>&nbsp;}<br>}<br>/**<br>&nbsp;* 控制器类,同时作为Interceptor的容器<br>&nbsp;* @author Administrator<br>&nbsp;*<br>&nbsp;*/<br>class Controller{<br>&nbsp;private $interceptors = array();<br>&nbsp;private $index = 0 ;<br>&nbsp;/**<br>&nbsp; * 调用Interceptor中的方法来执行<br>&nbsp; */<br>&nbsp;public function invoke(){<br>&nbsp;&nbsp;if ($this-&gt;index&lt;count($this-&gt;interceptors)){<br>&nbsp;&nbsp;&nbsp;$this-&gt;interceptors[$this-&gt;index++]-&gt;invoke($this,'invoke') ;<br>&nbsp;&nbsp;}else{<br>&nbsp;&nbsp;&nbsp;$this-&gt;index = 0 ;<br>&nbsp;&nbsp;&nbsp;$action = new Action() ;<br>&nbsp;&nbsp;&nbsp;$action-&gt;perform() ;<br>&nbsp;&nbsp;}<br>&nbsp;}<br>&nbsp;/**<br>&nbsp; * 增加Interceptor<br>&nbsp; * @param unknown_type $interceptor<br>&nbsp; */<br>&nbsp;public function addInterceptor($interceptor){<br>&nbsp;&nbsp;$this-&gt;interceptors[] = $interceptor ;<br>&nbsp;}<br>}</p>
<p><br>$controller = new Controller() ;</p>
<p>$controller-&gt;addInterceptor(new InterceptorImpl1()) ;<br>$controller-&gt;addInterceptor(new InterceptorImpl2()) ;<br>$controller-&gt;invoke() ;<br>?&gt;<br><br><span style="COLOR: red">代码运行结果:</span><br><br>Before method......111111111111111111<br>Before method......2222222222222<br>hello,fanyh!<br>After method......22222222222222222<br>After method......1111111111111111111<br><br>分析：<br>在实现MVC模式开发时，可以利用这种方式在action执行前对数据做一切处理，在经过action后再加处理<br>是不是有点java中的AOP的意思呢？<br></p>
<img src ="http://www.cnitblog.com/fanyh/aggbug/64720.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/fanyh/" target="_blank">fanyh</a> 2010-03-18 21:08 <a href="http://www.cnitblog.com/fanyh/archive/2010/03/18/64720.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>