随笔-3  评论-2  文章-0  trackbacks-0
  2010年6月14日

UML图


代码:
<?php
class Customer{
 private $id ;
 private $name ;
 private $address ;
 private $tel ;
 private static $observers = array() ;
 /**
  * @return the $id
  */
 public function getId() {
  return $this->id;
 }

 /**
  * @return the $name
  */
 public function getName() {
  return $this->name;
 }

 /**
  * @return the $address
  */
 public function getAddress() {
  return $this->address;
 }

 /**
  * @return the $tel
  */
 public function getTel() {
  return $this->tel;
 }

 /**
  * @param $id the $id to set
  */
 public function setId($id) {
  $this->id = $id;
 }

 /**
  * @param $name the $name to set
  */
 public function setName($name) {
  $this->name = $name;
 }

 /**
  * @param $address the $address to set
  */
 public function setAddress($address) {
  $this->address = $address;
 }

 /**
  * @param $tel the $tel to set
  */
 public function setTel($tel) {
  $this->tel = $tel;
 }
 /**
  *
  * @param Observer $observer
  */
 public static function attach($observer){
  if (!in_array($observer , self::$observers)){
   self::$observers[] = $observer ;
  }
 }
 /**
  *
  * @param Observer $observer
  */
 public static function detach($observer){
  foreach (self::$observers as $k => $item) {
   if ($item == $observer){
    unset(self::$observers[$k]) ;
   }
  }
 }
 /**
  * 通知所有的观察者
  */
 public function notify(){
  foreach (self::$observers as $observer) {
   $observer->update($this) ;
  }
 }
}
interface Observer{
 /**
  *
  * @param Customer $customer
  */
 public function update($customer) ;
 
}

class Address implements Observer{
 private $address = 'tianhe' ;
 /**
  *
  * @param Customer $customer
  */
 public function update($customer){
  if ($customer->getAddress() != $this->address){
   echo '地址变了...................' ;
   echo '<br>' ;
  }
 }
}

class Tel implements Observer{
 private $tel = 13602413192 ;
 /**
  *
  * @param Customer $customer
  */
 public function update($customer){
  if ($customer->getTel() != $this->tel){
   echo '电话变了...............' ;
   echo '<br>' ;
  }
 }
}
header("Content-Type:text/html;charset=utf-8") ;
$address = new Address() ;
$tel = new Tel() ;
Customer::attach($address) ;
Customer::attach($tel) ;

$customer = new Customer() ;
$customer->notify() ;

?>

本模式特性:
1.被观察者不需要知道自己被那些对象(观察者)观察着,观察者知道自己要观察谁(调用被观察者的attach()方法)
2.被观察者只需要在属性发生改变时,调用notify()方法,则所有在观察自己的对象都知道做出何种反应(观察者通过update()来做出反应)

posted @ 2010-06-14 23:54 fanyh 阅读(198) | 评论 (0)编辑 收藏
  2010年4月18日
男左女右

1)生命线:
生命纹--从大拇指与食指中间的掌边开始,往掌底走的纹路.
生命纹的长短并不代表寿命的长短,而是代表生命力的强弱,所以生命纹其实应该教做生命力纹.
生命纹长.深.红润-----生命力强,对疾病的抵抗力强,不容易生病;相反的,如果纹浅.弱,就比较衰弱.
纹粗---适合劳动或运动,纹细的适合用脑
生命纹包围的掌丘范围大的,也是精力充沛,爱欲旺盛;范围小的嬴弱,容易疲倦
生命纹开头(靠掌边)有链形纹的,儿童时期体弱多病
生命纹尾端有如流苏,要防老人病
生命纹上有岛纹,代表某一时间生病或住院,岛纹大小代表病情的轻重与时间长短


2)智能线

智能线至又称脑纹是掌相中最重要的一纹,中国手相中此纹代表自己,又称人纹.起点与生命线同,向小指方向走,至无名指与小指指缝间停最好,太短不够聪明,太长则精明过度,亦不好.
脑纹以深细为佳,表示思想能够集中,头脑聪明.
脑纹上有岛纹就表示思想不集中,记意力弱或脑部受挫.
脑纹起点有链行外在环境影响求学智能纹与生命纹起点一起, 两纹合为一,一段距离后才分开,表示内向,谨慎,考虑周详,
连的太长,则多虑,容易游豫不决.
如果生命线和智能线起点一起随后马上分开走,个性果断,能随机应变
如果两线分开有距离,是大胆外向的个性,天不怕地不怕.
如果两线起点分开超过半公分以上,就成莽撞不经大脑的个性了



3)感情线

感情纹又名天纹或父纹,从小指下掌边起向食指方向走,以走入食指与中指缝为中庸,
若一直前进至食指下,属于心灵之域,较注重精神的爱;进入中指下面,属肉体之爱,并不注重海誓山盟
如果在中指下往下弯,就爱得任性,不哲手段
若感情线长而且有分岔往下弯,则是舍一切为情牺牲
感情线深细的,感情也细腻,感情线粗浅的,感情也粗放;
感情线头端(掌边)如果上下都有像羽毛状的斜纹,表是这人很热情
若线下没羽毛纹,只有线上有,那是机智线,表示反应好能随机应变
感情纹如果是链行,多愁善感.
感情纹有岛形纹,如出现在无名指下,代表眼睛有问题,近视弱视或闪光.
若岛纹出现在其它位置,是感情上的困扰
感情线断裂,象征感情受到很大的挫折

posted @ 2010-04-18 21:35 fanyh 阅读(160) | 评论 (0)编辑 收藏
  2010年3月18日

<?php
class Action{

 public function perform(){
  echo 'hello,fanyh!<br>' ;
 }
}
/**
 * Interceptor接口
 * @author Administrator
 *
 */
interface Interceptor{
 /**
  * 在指定的方法之前执行
  */
 public function doBefore() ;
 /**
  * 在指定的方法之后 执行
  */
 public function doAfter() ;
}
/**
 * 所有Interceptor的基类
 * @author Administrator
 *
 */
abstract class AbstractInterceptor implements Interceptor{

 public final function invoke($object,$method,$args=null){
  $this->doBefore() ;
  if(method_exists($object,$method)){
   $object->$method($args);
  }
  $this->doAfter() ;
 }
}

/**
 * 定义一个Interceptor
 * @author Administrator
 *
 */
class InterceptorImpl1 extends AbstractInterceptor{
 /**
  *
  */
 public function doBefore() {
  echo 'Before method......111111111111111111<br>' ;
 }

 /**
  *
  */
 public function doAfter() {
  echo 'After method......1111111111111111111<br>' ;
 }
}
/**
 * 定义一个Interceptor
 * @author Administrator
 *
 */
class InterceptorImpl2 extends AbstractInterceptor{
 /**
  *
  */
 public function doBefore() {
  echo 'Before method......2222222222222<br>' ;
 }

 /**
  *
  */
 public function doAfter() {
  echo 'After method......22222222222222222<br>' ;
 }
}
/**
 * 控制器类,同时作为Interceptor的容器
 * @author Administrator
 *
 */
class Controller{
 private $interceptors = array();
 private $index = 0 ;
 /**
  * 调用Interceptor中的方法来执行
  */
 public function invoke(){
  if ($this->index<count($this->interceptors)){
   $this->interceptors[$this->index++]->invoke($this,'invoke') ;
  }else{
   $this->index = 0 ;
   $action = new Action() ;
   $action->perform() ;
  }
 }
 /**
  * 增加Interceptor
  * @param unknown_type $interceptor
  */
 public function addInterceptor($interceptor){
  $this->interceptors[] = $interceptor ;
 }
}


$controller = new Controller() ;

$controller->addInterceptor(new InterceptorImpl1()) ;
$controller->addInterceptor(new InterceptorImpl2()) ;
$controller->invoke() ;
?>

代码运行结果:

Before method......111111111111111111
Before method......2222222222222
hello,fanyh!
After method......22222222222222222
After method......1111111111111111111

分析:
在实现MVC模式开发时,可以利用这种方式在action执行前对数据做一切处理,在经过action后再加处理
是不是有点java中的AOP的意思呢?

posted @ 2010-03-18 21:08 fanyh 阅读(1783) | 评论 (2)编辑 收藏
仅列出标题