Stylistic question about inheritance
Irmen de Jong
irmen.NOSPAM at xs4all.nl
Thu Mar 31 22:40:32 CEST 2005
Andrew Koenig wrote:
> "Lonnie Princehouse" <finite.automaton at gmail.com> wrote in message
> news:1112300578.456411.274110 at f14g2000cwb.googlegroups.com...
>>If you try this sort of inheritance, I'd recommend writing down the
>>formal grammar before you start writing classes. Don't try to define
>>the grammar through the inheritance hierarchy; it's too easy to
>>accidentally build a hierarchy that can't be translated into a
> Understood. I was using expression trees as a contrived example, and really
> want to know about the Python community's stylistic preferences for defing
> such hierarchies that don't absolutely need a root.
I have used empty or near-empty base classes to be some sort of
class 'tag' for the derived classes.
Much like Java's Serializable interface; it adds nothing on
a functional level but you can check if a class has a 'tag'
by checking if it is an instance of the base class.
I don't know if this is good style in Python but I tend
to use it sometimes (probably because I do Java at work ;-)
More information about the Python-list