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();