Week 5 Live Lecture
Software Refactoring Exercise
Chapter 1: Software refactoring exercise
Strategy pattern
The Template Method pattern has reduced code duplication, at the cost of introducing coupling between the superclass and the subclass.
Make another copy of sequence.py
and this time name it strategy.py
. You can also copy from template.py
instead if you prefer.
Now, try to refactor the code in strategy.py
to reduce the duplication using a Strategy pattern.
You will also need to update the test code accordingly.
Run python3 strategy.py
to test that your code is behaving as expected.
And you are all done with the exercise! Well done!