Chapter 1: Software refactoring exercise

Strategy pattern

face Josiah Wang Rob Chatley

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.

Strategy Pattern

Run python3 strategy.py to test that your code is behaving as expected.

And you are all done with the exercise! Well done!