Get reference to "owner"

Jeff Shannon jeff at ccvcorp.com
Mon Mar 11 16:39:00 EST 2002


Robert Oschler wrote:

> Gerhard,
>
> Excellent!!!  Never expected to find a language that could do this and it
> something I've wanted very badly for a long time.  Yes that's exactly what I
> meant.  B knows about the A that owns it without having to artificially pass
> a reference of A to B during construction.

IMHO, this isn't a good idea.  Explicit is better than implicit, and if you need
to use a reference to the container object, then it's best to explicitly pass
that reference to the contained object on creation.  This also avoids the
limitation that someone else pointed out, that the solution that Gerhard Häring
came up with only finds the *creator*, not the container, and then only if that
creator uses 'self'.  It also allows you to change the containing object, if
there's ever a reason to do that (like moving an object from a Pending
collection to a Completed collection).

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list