Good solutions for passing around large numbers of arguments in a layered architecture?

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Jun 14 04:35:31 EDT 2010


Nathan Rice wrote:
> I've been running into a problem lately where I have an architecture like so:
>
> Main class -> facade/configuration class -> low level logic class.
>
> The main class is what the user interacts with.
>
> The facade/config class is responsible for loading and managing the
> lower level classes and providing a consistent interface to the main
> class.  It can be hot swapped in/out to drastically change the
> functionality of the main class.
>
> The low level logic classes are responsible for dealing with domain primitives.
>
>
> The issue I'm having is that I want advanced users to be able to pass
> extra configuration information to the facade and low level classes if
> need be, without the signature drastically changing with different
> facade classes.  Currently, I explicitly state parameters as much as
> possible at each level.  To deal with low level logic classes that
> have a large number of possible options I allow the caller to pass a
> dictionary of options for that class.  This leaves me with signatures
> that are upwards of 15 arguments long in some cases, the majority of
> them repeated in classes called from the main class.
>
> I've tried using args/kwargs, however I found it difficult to avoid
> having arguments in my signature re-ordered, and it is also a source
> of bugs.
>
> Has anyone come up with a good solution for dealing with arguments in
> situations like this where you'd like to encapsulate lower level stuff
> for neophyte users but make it easily available to advanced users?
>   
Use objects.

def foo(a,b,c,d, moreOptions=None):
    return

class MoreOptions:
    """Write the documentation about all the available options"""
    def __init__(self):
       self.opt1=None
       self.opt2=None


JM



More information about the Python-list mailing list