Session 7: Object Oriented Programing

Object Oriented Programing: classes, instance and class attributes, subclassing and inheritance.

Pre-class prep

Read:

Some Videos to watch:

Python Class Toolkit by Raymond Hettinger

https://youtu.be/HTLu2DFOdTg

https://speakerdeck.com/pyconslides/pythons-class-development-toolkit-by-raymond-hettinger

The Art of Subclassing by Raymond Hettinger

http://pyvideo.org/video/879/the-art-of-subclassing

The most salient points from that video are as follows:

  • Subclassing is not for Specialization
  • Classes and subclassing are for code re-use – not creating taxonomies
  • Bear in mind that the subclass is in charge

Note that the previous talk and this one were back to back at PyCon – but despite their contradictory titles – they have similar messages.

Stop Writing Classes

by Jack Diederich

http://pyvideo.org/video/880/stop-writing-classes

“If your class has only two methods – and one of them is __init__ – you don’t need a class”

In-class Activities

review mailman with testing

Exercises:

OO and classes are a big confusing topic when you are new to it.

So we’re going to learn hands-on by doing this exercise:

HTML Renderer Exercise

Post-class Activities

Finish the HTML render Exercise through step 3.

Look at the next session for reading, etc:

Session 8: Properties and Magic methods