Prototype.js PHP design mode prototype prototype mode code

Source: Internet
Author: User
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 (). "
";

The above describes the prototype.js PHP design pattern Prototype prototype code, including the prototype.js aspect of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.