The power of the pattern is that a subclass changes behaviour by overriding one step, never the skeleton. The run() method stays exactly as written in Step 1, the subclass just plugs a new transform into it.
Implement UpperPipeline, a subclass of Pipeline that uppercases every string during transform. Extract, load, and run are all inherited unchanged. Calling run() on an UpperPipeline still walks the same extract, transform, load skeleton, but now the transform step does real work.
Override only transform(data): return a new list with each string uppercased.
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):
data = self.extract()
data = self.transform(data)
result = self.load(data)
return result
class UpperPipeline(Pipeline):
def transform(self, data):
"""Uppercase every string in data (overrides the default identity transform)."""
# TODO: return a new list with each string uppercased
pass
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
The power of the pattern is that a subclass changes behaviour by overriding one step, never the skeleton. The run() method stays exactly as written in Step 1, the subclass just plugs a new transform into it.
Implement UpperPipeline, a subclass of Pipeline that uppercases every string during transform. Extract, load, and run are all inherited unchanged. Calling run() on an UpperPipeline still walks the same extract, transform, load skeleton, but now the transform step does real work.
Override only transform(data): return a new list with each string uppercased.
Press Run Tests or ββ© to check your solution.