复制代码 代码如下:
/**
* Prototype mode
*
* Use a prototype instance to specify the type of object to create. And create a new object by copying this prototype
*
*/
abstract class Prototype
{
private $_id = null;
public function __construct($id)
{
$this->_id = $id;
}
public function getID()
{
return $this->_id;
}
public function __clone() // magic function
{
$this->_id += 1;
}
public function getClone()
{
return clone $this;
}
}
class ConcretePrototype extends Prototype
{
}
//
$objPrototype = new ConcretePrototype(0);
$objPrototype1 = clone $objPrototype;
echo $objPrototype1->getID()."
";
$objPrototype2 = $objPrototype;
echo $objPrototype2->getID()."
";
$objPrototype3 = $objPrototype->getClone();
echo $objPrototype3->getID()."
";
http://www.bkjia.com/PHPjc/323625.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323625.htmlTechArticle复制代码 代码如下: ?php /*** Prototype pattern * * Use a prototype instance to specify the type of object to be created. And create a new object by copying this prototype **/ abstract class Prototype...