[Zope3-dev] zwiki: performance of findChildren()
Jeremy Hylton
jeremy@zope.com
28 Apr 2003 17:16:28 -0400
On Sat, 2003-04-26 at 14:36, Max M wrote:
> Why put the relation in the object? Isn't it better to have a container
> with different relations?
It clutters up the API. The fact that there is a relations object with
strange methods makes for more typing. In the example, a many-to-many
relation is just a set and a Python set now has a standard API. The
descriptor also eliminates the need to indirect through a family of
accessor methods.
Under the covers, we can implement the relation however we like. I
chose to hang the attributes directly on the object, but Shane would
probably want to put them in a separate table.
> # a relation object (a graph) exists "self.relations.developers_projects"
>
> class SoftwareProject(object):
>
> def __init__(self, name):
> self.name = name
>
> def __repr__(self):
> return "%s(%r)" % (self.__class__.__name__, self.name)
>
> def developers(self):
> return self.relations.developers_projects.get(self)
>
> def add_developer(self, developer):
> return self.relations.developers_projects.relate(self, developer)
Note that you haven't assigned to self.relations anywhere.
Jeremy