The Template Method

Step 1: The Template Method

An ETL pipeline always does the same three things in the same order: extract raw data, transform it, then load the result. The Template Method pattern captures that fixed order once, in a single method, so it can never be gotten wrong, while leaving each individual step open to change later.

The base Pipeline stores a source list and provides three default steps:

  • extract() returns a copy of the stored source list
  • transform(data) returns data unchanged (the identity transform)
  • load(data) returns data unchanged

Your job is the template method itself. Implement run() so it calls extract, then transform on that output, then load on that output, and returns the loaded result. This is the skeleton every future subclass will reuse untouched.

Hints
Starter code
class Pipeline:
    def __init__(self, source):
        self.source = source

    def extract(self):
        return list(self.source)

    def transform(self, data):
        return data

    def load(self, data):
        return data

    def run(self):
        """Template method: run extract, then transform, then load, in fixed order."""
        # TODO: spell out the fixed skeleton. Ask this object for its extracted
        # data, feed that through the transform step, feed that through the load
        # step, and hand the loaded value back. Always in that order and always
        # through self, so a subclass can override any single step later.
        pass
Write it on a laptop

The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.