最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP實(shí)現(xiàn)的觀察者模式實(shí)例

 更新時(shí)間:2017年06月21日 11:16:52   作者:北京流浪兒  
這篇文章主要介紹了PHP實(shí)現(xiàn)的觀察者模式,結(jié)合具體實(shí)例形式分析了php觀察者模式的定義與使用方法,需要的朋友可以參考下

本文實(shí)例講述了PHP實(shí)現(xiàn)的觀察者模式。分享給大家供大家參考,具體如下:

<?php
  //定義觀察者調(diào)用接口
  class transfer{
    protected $_observers = array();
    //注冊(cè)對(duì)象
    public function register($sub){
      $this->_observers[] = $sub;
    }
    //外部統(tǒng)一調(diào)用
    public function trigger(){
      if(!empty($this->_observers)){
        foreach($this->_observers as $observer){
          $observer->update();
        }
      }
    }
  }
  //觀察者接口
  interface obserable{
    public function update();
  }
  //實(shí)現(xiàn)觀察者
  class listen implements obserable{
    public function update(){
      echo 'now first time you need to do listen<br/>';
    }
  }
  class read implements obserable{
    public function update(){
      echo 'now first time you need to read<br/>';
    }
  }
  class speak implements obserable{
    public function update(){
      echo 'now first time you need to speak<br/>';
    }
  }
  class write implements obserable{
    public function update(){
      echo 'now first time you need to write<br/>';
    }
  }
  $transfer = new transfer();
  $transfer->register(new listen());
  $transfer->register(new read());
  $transfer->register(new speak());
  $transfer->register(new write());
  $transfer->trigger();

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP基本語(yǔ)法入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

兴海县| 芦山县| 应用必备| 光泽县| 保亭| 婺源县| 平顶山市| 高青县| 湖北省| 高青县| 巧家县| 长子县| 紫阳县| 镇远县| 秭归县| 吉林省| 漾濞| 霍山县| 山丹县| 凉山| 濉溪县| 紫金县| 天祝| 九龙城区| 湖北省| 沁阳市| 多伦县| 政和县| 庐江县| 阳曲县| 新宁县| 东阿县| 偃师市| 北京市| 且末县| 天全县| 桃江县| 杨浦区| 永安市| 洪湖市| 集安市|