Chinaunix首页 | 论坛 | 博客
  • 博客访问: 69703
  • 博文数量: 18
  • 博客积分: 492
  • 博客等级: 下士
  • 技术积分: 200
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-24 20:27
文章分类
文章存档

2011年(18)

分类: 系统运维

2011-04-11 18:03:34

  1. <?php
  2. /**
  3. * Observer
  4. */
  5. class BBCal
  6. {
  7.     public $message;
  8.     public $user_list = array();

  9.     public function register($user)
  10.     {
  11.         array_push($this->user_list, $user);
  12.     }

  13.     public function send($message)
  14.     {
  15.         foreach ($this->user_list as $val) {
  16.             $val->receive($message);
  17.         }
  18.     }
  19. }

  20. interface Rote
  21. {
  22.     public function receive($message);
  23.     public function display();
  24. }

  25. class Men implements Rote
  26. {
  27.     public $message;

  28.     public function receive($message)
  29.     {
  30.         $this->message = $message;
  31.         $this->display();
  32.     }

  33.     public function display()
  34.     {
  35.         echo 'this is man receive message:' . $this->message;
  36.     }
  37. }

  38. class Woman implements Rote
  39. {
  40.     public $message;

  41.     public function receive($message)
  42.     {
  43.         $this->message = $message;
  44.         $this->display();
  45.     }

  46.     public function display()
  47.     {
  48.         echo 'this is woman receive message:' . $this->message;
  49.     }
  50. }

  51. $man = new Men();
  52. $woman = new Woman();
  53. $bb = new BBcal();
  54. $bb->register($man);
  55. $bb->register($woman);
  56. $bb->send("please call 01012345678\n");
阅读(1237) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~