Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hello fellow monks,

I have a general OO design meditation...

In my application I have a very important configuration file that defines how the application acts in many ways. The application code is subdivided to many objects that don't interact much, but in most cases are there to encapsulate pieces of functionality. These objects are instantiated from the main flow and do their work.

Now, many of the objects need access to configuration data to do their work - sometimes it's quite a few configuration items for each object. The configuration data is encapsulated in an objects itself - the object reads the configuration data and provides access to it in an easy hash-like fashion.

I am wondering what is the best approach, design wise, to pass the configuration data into these objects. There are a few options:

  1. Pass only the relevant configuration items into each object. Pro: objects don't have to know about the configuration object. Cons: sometimes many items need to be passed into objects and it becomes very cumbersome.
  2. Pass a reference to the configuration object into each object that needs it. Pro: just one reference, and each object knows which items it needs to access. Cons: still feels a little cumbersome to pass the same objects into different objects.
  3. Keep a global singleton configuration object and access it directly from all objects. Pro: most minimal code-wise, no need to pass the object around. Cons: global data, hard to control access.

Now, all this becomes even more complicated when there are more than one configuration files, each with a distinct set of data that is not combinable, and some objects need access to different configuration objects.

Please share your thoughts - I'm sure it's quite a common issue. Is there a "pattern" for it ?

Thanks in advance


In reply to OO Design question: configuration by spurperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (16)
    As of 2014-08-27 15:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (242 votes), past polls