This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 1: Software refactoring exercise

Template Method pattern

face Josiah Wang Rob Chatley

Compare the FibonacciSequence and TriangleNumberSequence classes. There seems to be a lot of duplication, doesn’t it? Identify parts of the code that are similar, and parts that are different.

Make a copy of sequence.py and name it template.py.

Try to refactor the code in template.py to reduce the duplication using a Template Method pattern.

Template Method Pattern

When you are done, run python3 template.py to make sure that your code is still behaving correctly.