Our good friend Randall was talking about how he liked prototype inheritance such as that in JavaScript. He enjoyed how you can add, modify and remove methods from JavaScript classes and have them apply to all object instances.
Amazed as he was, he's now forcing me at gun point to write a post about it!
The first thing you have to understand about Python classes is that all they are is a collection of references to members. Methods are just function pointers that are referenced by the class, not embedded or copied into the class. This is why all methods require that the first parameter be self
, the current instance. Instances themselves contain the real state and reference the class. When you invoke a method on the instance it looks up what function to call.