object knows which object called it?

afriere at yahoo.co.uk afriere at yahoo.co.uk
Tue Apr 7 21:16:07 EDT 2009


On Apr 7, 2:53 am, "R. David Murray" <rdmur... at bitdance.com> wrote:

> I think the OO way to do this is to provide a method on A that does the
> right thing:
>
>     def Bfoo_func(self):
>         self.B.foo_func(self)
>
> Or maybe you could look at generic methods, which provide a way
> to do multiple dispatch.
+1

Which dispatch would itself be using methods to pass 'self' to the
receiving object.  Yes this would seem to be the obvious way to
establish two-way communication between objects.  I would be so bold
as to suggest that if the design the OP has adopted is not amenable to
this straightfoward approach, the design needs to be reassessed.



More information about the Python-list mailing list