Week 5 Live Lecture
Software Refactoring Exercise
Chapter 1: Software refactoring exercise
Warming up
Download sequence.py. Examine the code.
- There are two classes:
FibonacciSequence
andTriangleNumberSequence
. Try to understand what each class does. - What does the
term()
method of each class return? - How is the
length
attribute used in each class? - The
__iter__()
and__next__()
methods allow Python to treat these classes as iterable sequences. - Look at the test code at the end of the script to get a feel of how both classes are used.
Run the code (python3 sequence.py
). It should work and generate the correct sequences.