簡介:這是php設計模式 Prototype (原型模式)的詳細頁面,介紹了和php,有關的知識、技巧、經驗,和一些php源碼等。
class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=339371' scrolling='no'>
1 <?php
2 /**
3 * 原型模式
4 *
5 * 用原型執行個體指定建立對象的種類.並且通過拷貝這個原型來建立新的對象
6 *
7 */
8 abstract class Prototype
9 {
10 private $_id = null;
11
12 public function __construct($id)
13 {
14 $this->_id = $id;
15 }
16
17 public function getID()
18 {
19 return $this->_id;
20 }
21
22 public function __clone() // magic function
23 {
24 $this->_id += 1;
25 }
26
27 public function getClone()
28 {
29 return clone $this;
30 }
31 }
32
33 class ConcretePrototype extends Prototype
34 {
35 }
36
37 //
38 $objPrototype = new ConcretePrototype(0);
39 $objPrototype1 = clone $objPrototype;
40 echo $objPrototype1->getID()."<br/>";
41 $objPrototype2 = $objPrototype;
42 echo $objPrototype2->getID()."<br/>";
43
44 $objPrototype3 = $objPrototype->getClone();
45 echo $objPrototype3->getID()."<br/>";
愛J2EE關注Java邁克爾傑克遜視頻站JSON線上工具
http://biancheng.dnbcw.info/php/339371.html pageNo:8