creational

Prototype

Create new objects by copying (cloning) an existing object.

Occasionally the cheapest way to make an object is to copy one you already have. If construction is genuinely expensive — it hits a database, parses a file, or runs heavy computation to reach a particular state — then cloning a fully-formed instance and tweaking a few fields beats rebuilding from scratch. Prototype treats existing objects as templates you duplicate on demand.

A photocopier — you don't retype a document for each copy; you duplicate the original.

Key Concepts

1
Each object exposes a clone() method that returns a copy of itself, so clients duplicate prototypes instead of calling constructors and reconstructing state. Because the object copies itself, it can reach its own private fields, and the client stays decoupled from the concrete classes — it just asks any prototype to clone. A registry of pre-configured prototypes can act as a lightweight factory: register a few canonical instances, then clone whichever one a request needs.
clone()
2
This fits game objects spawned by the thousand, document templates, cached records you want to hand out without re-fetching, and any situation where you'd otherwise build a complex class hierarchy just to vary initial state. The pitfall to respect is shallow versus deep copy. A shallow clone copies references, so the original and the copy share their nested objects — mutating one silently mutates the other. Decide deliberately which fields need a deep copy, and be careful with cyclic references, which naive deep-clone routines can loop on forever.