Chapter 14. Prototype Pattern

There is one particular thing that I've been reminded of over and over again while programming in object-oriented languages. This reminder peaks its head above all the rest with its ever-insistent mentions in most books and articles. What is the point that no object-oriented programmer should forget? Keep your objects small, modular, uncoupled, and streamlined. There are two times when one might find contradictory objects, however:

  • When inheriting code from someone else. Sometimes you just don't have the time or budget to refactor this code into something that you find more acceptable.

  • When code just can't be slimmed down any further. This is pretty concrete. The expense comes in when this object has to be uniquely created and used multiple times in one code stream.

In situations where a resource intensive object needs to be created often, the Prototype Pattern provides a welcome route to faster execution.

Name: Prototype

The Prototype Design Pattern creates objects in such a way that an initial object or prototype can be copied and cloned more efficiently than creating a new instance.

Get Professional PHP Design Patterns 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.