Tree views - Best design practices

Filip Gruszczyński gruszczy at
Thu Jan 8 15:53:00 CET 2009


I have certain design problem, which I cannot solve elegantly. Maybe
you know some good design patterns for this kind of tasks.


We have a model which has two kinds of objects: groups and elements.
Groups can hold other groups (subgroups) and elements. It's a simple
directory tree, for example. We would like to display it in a tree
view (which sound good for this kind of model). What is more required,
for groups and elements there are different sets of operations, which
should be available under right click. For example for group, there
should be operations: 'add element' and 'add group', and for element
there should be 'change properties'.

Do you know any smart way to achieve this? The simplest way is to ask
for the class and display operations accordingly. But from the first
day with OO programming I have heard, that asking for class is wrong.
But I can hardly see any easy and more maintainable solution for this
problem. Could you help me with this?

Filip Gruszczyński

More information about the Python-list mailing list