CodePark/ questions / Behavioral patterns
START PRACTICINGPRACTICE
Backend question · Software design & patterns › Behavioral patterns

Which pattern is this?

abstract class ReportJob {
  async run() {
    const rows = await this.fetchRows();
    const file = this.format(rows);
    await this.upload(file);
  }
  protected abstract fetchRows(): Promise<Row[]>;
  protected abstract format(rows: Row[]): Buffer;
  protected async upload(file: Buffer) { /* default S3 upload */ }
}
Template Method

Template Method fixes the skeleton (the main steps) of an algorithm in a base class. Subclasses override specific steps, through inheritance. "Strategy" is the tempting wrong answer. It swaps a whole algorithm through composition, by passing in an object. It does not override steps of a base class.