© Kelt Dockins 2017

Kelt Dockins, Design Patterns in PHP and Laravel, 10.1007/978-1-4842-2451-9_6

6. Prototype

Kelt Dockins

(1)Dolph, Arkansas, USA

$> git checkout prototype

Intent

Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.1

Applications

Use the prototype pattern when you want to fork and modify existing objects. A good use for this pattern is when you want to avoid the construction of a class that takes a lot of time or is complicated to create initially. An example of an object with a costly creation is one that uses a web service to fetch data. Once you have the data, though, you no longer need to fetch data from the web service; you just clone the data. There is another ...

Get Design Patterns in PHP and Laravel now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.