software design question

Uwe Mayer merkosh at hadiko.de
Sat Feb 7 18:15:42 EST 2004


Josiah Carlson wrote:

>> So the question is rather: how to make a better design?
[...]
> Pass what is needed.  If you can't pass what is needed when external
> module classes are initialized, then set the attribute later.
> 
> c1instance.attribute = value

Ok, that is a way of enabling the circular dependency, but that doesn't
really get rid of it. The main program still needs the module and the
module may now access parts from the main program using the passed
parameters or the later set attributes.

That was my first approach, passing what's needed. But if module1 delegates
some task to another module, then again all args must be passed to that
module and so forth. 
Now currently I've got about 7 such modules that may need to interact then I
end up in passing to each level of delegation an increasingly _huge_
parameter list and that's where I stopped thinking in that direction.

My current solution to this is to pass the instances that may need to be
publicly known as value in a key:value pair, stored in a dictionary. Thus
something like:

>>> import singleton
>>> single = singleton.Singleton()
>>> single['main'] 

returns the appropriate instance.

Ciao
Uwe



More information about the Python-list mailing list