Home > Backend Development > PHP Tutorial > PHP design pattern Prototype (prototype mode) code_PHP tutorial

PHP design pattern Prototype (prototype mode) code_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:28:11
Original
802 people have browsed it

复制代码 代码如下:

/**
* 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()."
";

www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template