Sofware Refactoring Exercise
Chapter 1: Software refactoring exercise
Template Method pattern
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.
When you are done, run python3 template.py
to make sure that your code is still behaving correctly.