go ahead... be a heretic | |
PerlMonks |
Re^3: Singletons and Inheritanceby Joost (Canon) |
on Jul 20, 2004 at 11:28 UTC ( [id://375873]=note: print w/replies, xml ) | Need Help?? |
It's just my personal preference - I've run into too many situations where in the end you do NOT want a forced singleton. So I'd do:
And if any code calls $class->new() directly, they'll get another instance which getInstance knows nothing about, so it doesn't interfere. Also, I think splitting up the code like this makes it a lot clearer. OTOH, if you have a good reason to always disallow more than one instance (I can only think of interfaces to hardware), you could rename it so that getInstance is named new() and new() is named _new() or something (and don't document _new() in the public API).
In Section
Seekers of Perl Wisdom
|
|