Designing using objects#

For a more detailed treatment of classes see Part IV of Lutz. (2013). Learning Python. 5th Ed. O’Reilly.

To get the most out of python when coding algorithms and models it is essential that you understand the basics of python classes and object orientated programming (OOP). The key takeaways from this section are that class aid code reuse and design (although when used unwisely they can overcomplicate designs!). We will try and do this in a fun way so you can see the benefits.

In this section you will learn:

  • How to instantiate multiple instances of a class.

  • How to declare a class and define a class constructor method.

  • What is meant by class attributes and methods.

It is worth noting that in python you don’t have to use classes you can actually achieve everything with functions. However, the abstraction benefits of OO are really important for the design and organisation of complex projects.