Creating our own classes of objects
The two lists of data values that HQ asked us to get—cheese consumption and W75 deaths—form two objects that are very similar. They seem to be two instances of the same class of things.
In this case, the class of things seems to have annual statistics. They're collections with a consistent structure of a year and a measurement. Both these annual statistics objects have a common set of operations. Indeed, the operations are pretty tightly bound to the measurement, and they are not at all bound to the year number.
Our collection of statistical functions is not very tightly bound to our data at all.
We can improve the binding between data structure and processing through a class definition. If we define the general features of a class of objects that we can call annual statistics, we can create two instances of this class and use the defined methods on the unique data of each instance. We can easily reuse our method functions by having multiple objects of the...