Php design mode Prototype (Prototype) code. Copy the code as follows :? Php ** prototype ** specifies the object type to create with the prototype instance, and creates a new object by copying the prototype ** abstractclassPrototype
The code is as follows:
/**
* Prototype
*
* Use a prototype instance to specify the object type and copy the prototype to create a new object.
*
*/
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 ()."
";
The http://www.bkjia.com/PHPjc/323625.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323625.htmlTechArticle code is as follows :? Php/*** Prototype ** use a Prototype instance to specify the type of the object to be created, and copy the Prototype to create a new object **/abstract class Prototype...