Am 13.09.2012 14:51, schrieb andrea crotti:
I am in a situation where I have a class Obj which contains many
attributes, and also contains logically another object of class
Dependent.
This dependent_object, however, also needs to access many fields of the
original class, so at the moment we did something like this:
[...]
I could of course passing all the arguments needed to the constructor of
Dependent, but it's a bit tedious..
Jean-Michel already asked a good question, i.e. whether those two
classes should be separate at all. I'll ask a similar question: Can't
the shared data be put into a third, separate class? That way passing
all the needed arguments wouldn't be tedious any more. Also, it makes
clear that both outer and inner class depend on common data, but that
the inner class doesn't depend on the outer beyond that.
Now, just to get at least something Python-specific into this, you could
override the __getitem__ of the inner class and transparently look up
the item in the outer class if the inner class doesn't have it.
Uli
--
http://mail.python.org/mailman/listinfo/python-list