Copy CodeThe code is as follows:
/**
* Prototype mode
*
* Use the prototype instance to specify the kind of object to create. and create new objects 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);
$objPrototype 1 = clone $objPrototype;
echo $objPrototype 1->getid (). "
";
$objPrototype 2 = $objPrototype;
echo $objPrototype 2->getid (). "
";
$objPrototype 3 = $objPrototype->getclone ();
echo $objPrototype 3->getid (). "
";
http://www.bkjia.com/PHPjc/323625.html www.bkjia.com true http://www.bkjia.com/PHPjc/323625.html techarticle Copy the code as follows: PHP/** * Prototype Mode * * Use the prototype instance to specify the kind of object created. And by copying this prototype to create a new object * */abstract class Prototype ...