Tree views - Best design practices

Jonathan Gardner jgardner at
Thu Jan 8 22:25:36 CET 2009

On Jan 8, 1:00 pm, "Filip Gruszczyński" <grusz... at> wrote:
> Is it really any better than asking for class? I mean, if I need to
> add another class to a hierarchy which behaves differently, will it be
> more flexible (actually you have to add another method to every class
> and check for in the gui). I believe it's just the same as asking for
> the class, but we hide it under static methods. It's no different
> though.

Yes. There is a difference between the interface of an object (namely,
what methods and attributes it has and what their semantic meaning is)
and the class of an object (what methods and attributes it has and how
they are implemented.)

In general, you shouldn't be asking about an object's class. Down the
road, you may want to use an object that isn't of the same class but
does support the interface.

Consider how the file object is used in Python. Pretty much every
place you can use a file object you can use a StringIO, right? That's
because StringIO supports the file interface while it isn't a file.

You may want to read up on 'duck typing' to get a better sense of why
this is important.

More information about the Python-list mailing list