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: PrototypeThe 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. |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access