PHP design pattern prototype pattern, design pattern prototype_PHP tutorial

WBOY
Release: 2016-07-12 08:58:07
Original
723 people have browsed it

php design mode prototype mode, design mode prototype

Prototype mode has a similar function to engineering mode, both are used to create objects.

Different from the implementation of the engineering mode, the prototype mode first creates a prototype object, and then Tonggu clones the prototype object to create a new object. This eliminates the need for repeated initialization operations when creating classes.

Prototype pattern is suitable for the creation of large objects. Creating a large object requires a lot of overhead. If it is new every time, it will consume a lot of money. The prototype mode only needs a memory copy.

index.php

<span>$prototype</span> = <span>new</span><span> Baobab\Canvas();
</span><span>$prototype</span>-><span>init();

</span><span>$canvas1</span> = <span>clone</span> <span>$prototype</span><span>;
</span><span>$canvas1</span>->rect(3,6,4,12<span>);
</span><span>$canvas1</span>-><span>draw();
</span><span>$canvas2</span> = <span>clone</span> <span>$prototype</span><span>;
</span><span>$canvas2</span>->rect(3,6,4,12<span>);
</span><span>$canvas2</span>->draw();
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1105141.htmlTechArticlephp design mode prototype mode, design mode prototype prototype mode is similar to engineering mode, both are used to create objects. Different from the implementation of engineering mode, the prototype mode first creates a...
Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!