elTriberium has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks!
I often run into the situation where I need access to a single object from many other objects. For example in my current project I have a config object, which parses an XML configuration file and several modules need to access this data. I want to avoid parsing the XML file over and over again, so I just want to have a single instance of this Config object.
I'm using Moose and know that I could use MooseX::Singleton to create a singleton config object, but also have heard several warnings against using singletons. I was in the same situation before, where I made my Log module a singleton, but then wanted to have different logfiles for different modules and ran into issues with just having a singleton object.
So this is more a general design question: How would you design access to a module that is required by multiple modules? I want to avoid passing that module back and forth when instantiating the calling objects as that would also quickly grow cumbersome
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Access to single object from multiple other objects
by tobyink (Canon) on Oct 31, 2013 at 08:56 UTC | |
|
Re: Access to single object from multiple other objects
by locked_user sundialsvc4 (Abbot) on Oct 30, 2013 at 20:44 UTC | |
|
Re: Access to single object from multiple other objects
by moritz (Cardinal) on Oct 31, 2013 at 16:38 UTC | |
|
Re: Access to single object from multiple other objects (argument)
by Anonymous Monk on Oct 30, 2013 at 23:17 UTC | |
|
Re: Access to single object from multiple other objects
by kschwab (Vicar) on Nov 02, 2013 at 21:21 UTC | |
|
Re: Access to single object from multiple other objects
by elTriberium (Friar) on Oct 31, 2013 at 19:55 UTC | |
by Anonymous Monk on Nov 01, 2013 at 03:55 UTC |