tl;dr Prototype has always been one of those patterns that nobody in the strongly-typed OO world really spent much time thinking about, but when Javascript came along and forcibly (re-)introduced people to the concept of prototypical construction, it brought some new life to the idea.

Problem

Context

Use the Prototype pattern when a system should be independent of how its products are created, composed, and represented; and

The big question that emerges from Prototype is "how deep"--that is, when we clone a given object, are we cloning just that object, or all of its associated/referenced objects, as well? Put into practical terms, if we clone the Person object, which holds a field for "spouse" and a field for a collection of "children" Person objects, do we clone the Person's spouse and any children objects as well? Are we cloning the entire family, or just the individual Person object? In some cases, if the referenced object is a Value Object,

Solution

A couple of interesting questions emerge when thinking about implementing a Prototype:

Implementations

Consequences

Relationships

Variations

Last updated: 09 March 2022

Tags: pattern   creational