A Different Subclass, Same Skeleton

Step 3: A Different Subclass, Same Skeleton

To prove the skeleton is truly reusable, add a second, unrelated subclass. A completely different transform still slots into the same run() with zero changes to it.

Implement SumPipeline, a subclass of Pipeline whose transform reduces a list of numbers to a single-element list holding their sum. So a source of [1, 2, 3, 4] runs to [10]. Load and run are inherited unchanged.

Override only transform(data): return a one-element list containing the sum of data.

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):
        data = self.extract()
        data = self.transform(data)
        result = self.load(data)
        return result


class UpperPipeline(Pipeline):
    def transform(self, data):
        return [s.upper() for s in data]


class SumPipeline(Pipeline):
    def transform(self, data):
        """Reduce the numbers in data to a single-element list holding their sum."""
        # TODO: return [sum(data)]
        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.