CHAPTER 19

image

Prototype Patterns

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

Concept

The prototype pattern provides an alternative method for instantiating new objects by copying or cloning an instance of an existing one. Creating a new instance, in a real-world scenario, is normally treated as an expensive operation. This pattern helps us to deal with this issue. Our focus here is to reduce the expense of this creational process of a new instance.

Real-Life Example

Suppose we have a master copy of a valuable document. We want to make some change to it to ...

Get Java 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.