⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 observable.php

📁 Professional PHP5 code for this book
💻 PHP
字号:
<?phpabstract class Observable {  private $observers = array();  public function addObserver(Observer & $observer) {         array_push($this->observers, $observer);  }  public function notifyObservers() {         for ($i = 0; $i < count($this->observers); $i++) {                 $widget = $this->observers[$i];                 $widget->update($this);         }     }}class DataSource extends Observable {  private $names;  private $prices;  private $years;  function __construct() {         $this->names = array();         $this->prices = array();         $this->years = array();  }  public function addRecord($name, $price, $year) {         array_push($this->names, $name);         array_push($this->prices, $price);         array_push($this->years, $year);         $this->notifyObservers();  }  public function getData() {         return array($this->names, $this->prices, $this->years);  }}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -