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.
Read more