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:
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.
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
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
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:
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.
Press Run Tests or ββ© to check your solution.