Use a prototype instance to specify the type of the object to be created, and copy the prototype to create a new object. Copy codeThe 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 content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service