Tree views - Best design practices

Filip Gruszczyński gruszczy at
Thu Jan 8 22:00:04 CET 2009

>    class Element(object):
>        @staticmethod
>        def is_leaf(): return True
>        @staticmethod
>        def is_branch(): return False
>    class Group(object):
>        @staticmethod
>        def is_leaf(): return False
>        @staticmethod
>        def is_branch(): return True
> Of course, you have to give priority to one or the other, in case an
> object thinks it is both.
>    if thing.is_branch():
>        # Treat it like a branch
>    elif thing.is_leaf():
>        # Treat it like a leaf
> I believe this is a simpler method than checking a single attribute
> for a name.

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

Filip Gruszczyński

More information about the Python-list mailing list