Prototype pattern (source code)

= Prototype pattern
{wiki}

Expose a cloning operation through a common <object interface> and create new objects by asking a configured prototype for a copy. Concrete prototypes implement the copy operation; the client need not name their concrete <software classes>. This is useful when creation depends on runtime configuration or expensive reusable initial state. The contract must specify whether nested mutable data requires a <deep copy>; copying only outer fields can preserve unintended <reference aliasing>.