← Back to scenarios
ScenarioCatalog DB

Data import template

Use a standard import pipeline while file formats customize parsing and validation.

Problem

A data-import system must preserve one processing pipeline while allowing format-specific parsing and validation steps to vary without duplicating common import behavior.

Related patterns

Implementations

Template Method

TypeScriptApplication

TypeScript order processing template

Keeps the order-processing sequence fixed while subclasses customize validation and fulfillment for different order types.

TypeScript
abstract class OrderProcessor {
  async process(orderId: string) {
    await this.validate(orderId);
    await this.reserveInventory(orderId);
    await this.fulfill(orderId);
  }

  protected abstract validate(orderId: string): Promise<void>;

  protected async reserveInventory(orderId: string) {
    console.log(`Reserving inventory for ${orderId}`);
  }

  protected abstract fulfill(orderId: string): Promise<void>;
}

class DigitalOrderProcessor extends OrderProcessor {
  protected async validate(orderId: string) {
    console.log(`Validating digital order ${orderId}`);
  }

  protected async fulfill(orderId: string) {
    console.log(`Emailing download link for ${orderId}`);
  }
}

Associated technologies