in reply to Multiple Inheritance - Howto marry tie::refhash::nestable with class::singleton
Class::Singleton and its relatives really don't do that much for you. Look under the hood and you won't find that much code. The concept of a singleton is very simple and you can just implement the 5 lines of code in your module. You can see my article on Singletons in The Perl Review 0.1.
The Cult of Design Patterns seems to think that you should make the end programmer realize he is using a singleton, and instead of new() use something like get_instance(). I think that's the wrong way to go: in most cases the end programmer shouldn't have to think about that as long as everything works.
That doesn't matter much in your case since the magic is hidden in the Tie interface. Before you start doing things in TIEHASH, however, you need to check if you already have the instance, and if you do, simply return it. Don't make a new object then check for an old one.
|
|---|