in reply to Re^4: what is a propper way to make a chunk of data accessible to all my packages for retrieval and modification ?
in thread what is a propper way to make a chunk of data accessible to all my packages for retrieval and modification ?

So you're suggesting a singleton after all ? ;)
  • Comment on Re^5: what is a propper way to make a chunk of data accessible to all my packages for retrieval and modification ?

Replies are listed 'Best First'.
Re^6: what is a propper way to make a chunk of data accessible to all my packages for retrieval and modification ?
by Aristotle (Chancellor) on Mar 04, 2006 at 19:35 UTC

    No, I’m suggesting a class that can be instantiated as many times as you want, like any other class, which is exactly what a singleton is not, then passing it around everywhere. If you have wildly unrelated things you’d be putting into this class if you just translated your current scheme 1:1, then instead, create different classes for each thematically grouped set of things, and pass them around as needed.

    Ideally you should be able to run multiple concurrent instances of any of your classes with a different configuration each.

    The goal is to avoid creating dependencies on the configuration objects such that you’ll end up having to be careful about the order in which you call methods due to side effects – that’s exactly the problem created by globals.

    Makeshifts last the longest.

      I typically see a configuration object as some sort of mostly read-only data store, typically the sort of stuff a singleton is good for... Sure you can instantiate it as many times as you fancy to, but after all isn't the whole ideo of a singleton about sharing the same information ?
      I really don't buy this "singletons sucks" stuff, at least for configuration object :)
        I really don't buy this "singletons sucks" stuff, at least for configuration object :)

        For me the problem is that if there are dozens of:

        my $config = MySingletonConfigurationClass->instance; my ($foo, $bar) = ( $config->foo, $config->bar );

        sprinkled all around my code overriding things for testing, tweaking configuration based on the context, etc. all become much harder than if I'd passed in my own configuration object, used dependency injection, or whatever.

        Most people seem to use singletons as big-fat-globals in disguise - and give themselves (or the poor souls who have to maintain their code) all the problems that globals give you.

        Take a look at http://del.icio.us/adrianh/singleton for some singleton rants.