|There's more than one way to do things|
Access to single object from multiple other objectsby elTriberium (Friar)
|on Oct 30, 2013 at 19:21 UTC ( #1060420=perlquestion: print w/replies, xml )||Need Help??|
elTriberium has asked for the wisdom of the Perl Monks concerning the following question:
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
Back to Seekers of Perl Wisdom