Accessing container's methods

Thomas 'PointedEars' Lahn PointedEars at web.de
Mon Dec 7 13:46:12 EST 2015


Tony van der Hoff wrote:

> I have a class A, containing embedded embedded classes, which need to
> access methods from A.

Let the name of the "embedded class" (which is not embedded at all in your 
example code) be E.  You could either store the information in the E 
instance upon or after construction, or you could pass a reference to the A 
instance to the E instance’s method, so that you can call the A instance’s 
public methods from the E instance’s methods.

But consider the Law of Demeter.

> I don't really want to make Actor a sub-class (is-a; it isn't) of Monty;
> that would raise all sorts of other problems.

It would simply be wrong.  Monty (Python) is (literally) a group of Actors.
 
-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.



More information about the Python-list mailing list