looking for a pattern

Geoff Gerrietts geoff at gerrietts.net
Fri Feb 7 11:55:43 EST 2003


I'm looking for a pattern. I don't have one in my mental filing
cabinet yet, and I'm not sure how to start hunting for it, so I
figured my first stop would be to ask here.

Assume I have a hierarchy of instances, grandpa -> papa -> boy, with the
standard biological constraints (one male parent, zero or more sibs).
I want boy to know who his papa is (sue me, I'm traditional that way),
as well as vice versa.

Now, the "traditional" way to do this would be through a backlink --
boy has an ivar parent that gets hooked up at instantiation time. But
this creates a cycle, which I know to be a Bad Thing in my unfortunate
1.5.2 world.

Is there a better way to solve this problem that doesn't create a
cycle, or is the backlink the best bet? For that matter, with the
advent of the new garbage collection, is it even worth avoiding cycles
in newer versions of the interpreter?

Thanks,
--G.

-- 
Geoff Gerrietts <geoff at gerrietts dot net>       http://www.gerrietts.net/
karma police arrest this man he speaks in maths -- Radiohead, "Karma Police"





More information about the Python-list mailing list