creational

Prototype

Specify the kinds of objects to create using a prototypical instance, and create new objects by cloning that prototype.

Problem

creational

Creating new objects from scratch can be expensive or repetitive when the system needs many similar variants.

Integration notes

Prototype is useful when object creation is expensive, when many near-identical objects are needed, or when cloning preconfigured templates is simpler than rebuilding them.

Tradeoffs

  • Can be difficult if the object graph contains deep references that need custom clone behavior
  • May require careful handling of mutable state to avoid shared-reference bugs

Languages

typescript, java, python, angular, react, react-native, csharp, dotnet

Platforms

Web, Backend, Mobile, UI kits, Cross-platform systems

Variants

Scenarios

Document template clone

An editor clones a preconfigured document template to quickly create new reports with the same layout and styling.

Language examples

Core languages

Frameworks and libraries

Document template clonetypescript

The document prototype lets the editor clone a prepared template and then customize the copy without rebuilding the document from scratch.

TypeScript
interface DocumentPrototype {
  clone(): DocumentPrototype;
  render(): string;
}


class ReportDocument implements DocumentPrototype {
  constructor(
    public title: string,
    public author: string,
    public sections: string[],
  ) {}


  clone(): DocumentPrototype {
    return new ReportDocument(this.title, this.author, [...this.sections]);
  }


  render(): string {
    return `${this.title} by ${this.author}: ${this.sections.join(", ")}`;
  }
}


const template = new ReportDocument("Quarterly Report", "Atlas Team", [
  "Summary",
  "Metrics",
  "Conclusion",
]);


const copy = template.clone() as ReportDocument;
copy.title = "Quarterly Report Copy";
copy.sections.push("Appendix");


console.log(template.render());
console.log(copy.render());

Real-world examples

  • Template-based editors: Writing tools and content systems often duplicate document templates or slide layouts instead of recreating them from scratch.
  • Game entity spawning: Games frequently clone enemies, NPCs, or loadout presets to quickly generate many similar entities.
  • Configurable product variants: E-commerce systems often duplicate a base product configuration and then tweak colors, sizes, or pricing rules.