← Back to scenarios
ScenarioCatalog DB

Product config clone

Clone a product-configuration prototype to generate similar catalog items with small differences.

Problem

A commerce system must create many similarly configured catalog items without reconstructing shared configuration from scratch or coupling item-creation workflows to concrete product types.

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