<?php $users = new \IMooc\AllUser(); foreach ($users as $user) { echo $user->name . "\n"; $user->serial_no = rand(10000, 99999); } $id = 1; $proxy = new \IMooc\Proxy(); $proxy->getUser($id); $proxy->setUser($id, array('name' => 'wang'));
// } // class Observer2 implements Observer // { // public function update($event_info = null) // { // echo "逻辑2<br/>\n"; // } // } // $event = new Event(); // $event->addObserver(new Observer1); // $event->addObserver(new Observer2); // $event->trigger(); // // 原型模式 // $prototype = new IMooc\Canvas(); // $prototype->init(); // // 装饰器模式 // $prototype->addDecorator(new \IMooc\ColorDrawDecorator); // $canvas1 = clone $prototype; // $canvas1->rect(3, 6, 4, 12); // $canvas1->draw(); // $canvas2 = clone $prototype; // $canvas2->rect(3, 6, 4, 12); // $canvas2->draw(); // // 迭代器模式 // $users = new \IMooc\AllUser; // foreach ($user as $key => $value) { // # code... // } $proxy = new \IMooc\Proxy(); $proxy->getUserName($id); $proxy->setUserName($id, $name);