← Back to scenarios
ScenarioCatalog DB

Document template clone

Clone a preconfigured document template to create new reports with shared layout and styling.

Problem

An editor must create many similarly configured reports without repeatedly rebuilding complex layout and styling settings or coupling clients to a concrete document implementation.

Related patterns

Implementations

Prototype

TypeScriptApplication

Prototype in TypeScript

Creates independent deployment templates by cloning a configured prototype and changing only the environment-specific values.

TypeScript
interface Prototype<T> {
  clone(): T;
}

class DeploymentTemplate implements Prototype<DeploymentTemplate> {
  constructor(
    readonly serviceName: string,
    readonly replicas: number,
    readonly labels: Record<string, string>,
  ) {}

  clone(): DeploymentTemplate {
    return new DeploymentTemplate(
      this.serviceName,
      this.replicas,
      { ...this.labels },
    );
  }

  withEnvironment(environment: string): DeploymentTemplate {
    const copy = this.clone();

    return new DeploymentTemplate(
      copy.serviceName,
      copy.replicas,
      {
        ...copy.labels,
        environment,
      },
    );
  }
}

const baseTemplate = new DeploymentTemplate(
  "billing-api",
  2,
  { owner: "payments" },
);

const productionTemplate = baseTemplate.withEnvironment("production");

Associated technologies