Daniel Roy Greenfeld

Daniel Roy Greenfeld

About | Articles | Books | Jobs | News | Tags

Inheritence is fun!

This was originally posted on blogger here.

Imagine this view in python:

class MyFirstForm(formbase.PageForm): lots and lots of finicky code.

Now lets say we want to capture everything in that view, but give it a slightly different behavior. How about this?
class MySecondForm(formbase.SubPageForm,FeedbackForm): pass

So what does this do?

Well, in Python what this does is make the second class inherit the properties of a similar base class, then overwrite it with the properties of the first form. The order of precedence in inheritance in Python is very clear and straightforward. The result is a wonderful case of object oriented code reuse.

I believe Ruby does it in a very similar fashion.


Tags: ruby python java legacy-blogger