looking for a pattern
Geoff Gerrietts
geoff at gerrietts.net
Fri Feb 7 16:30:04 EST 2003
Quoting Carlos Ribeiro (cribeiro at mail.inet.com.br):
> You can use the list to hold all objects, or simply use the list to keep a few
> auxiliary links, but you got the idea. Of course, you are going to be careful
> and do the link management yourself, but this technique allows you to avoid
> explicit circular references.
This is sorta the pattern I was looking for, I think.
I can see an alternate implementation along the lines of keeping all
the objects in a collection / dictionary by id(obj), and managing the
parent links on the individual objects. Might look like:
Collection = {}
class FamilyMember:
def __init__(self, parent_id):
Collection[id(self)] = self
self._parent_id = parent_id
def parent(self):
return Collection.get(self._parent_id)
I think that might be the near-equivalent of a weakref, in 1.5.2?
Except the Collection needs to be explicitly managed.
--G.
--
Geoff Gerrietts "People talk fundamentals and superlatives
<geoff at gerrietts net> and then make some changes of detail."
http://www.gerrietts.net --Oliver Wendell Holmes Jr
More information about the Python-list
mailing list