Possible Duplicate:
Who needs singletons?
I always write with respect to best practice, but I also want to understand why a given thing is a best practice.
I've read on in an article (I unfortunately don't remember) that singleton classes are prefered to be instantiated, rather than being made with static functions and accessed with the scope resolution operator (::). So if I have a class that contains all my tools to validate, in short:
class validate {
private function __construct(){}
public static function email($input){
return true;
}
}
I've been told this is considered bad practice (or at least warned against), because of such things as the garbage collector and maintenance. So what the critiques of the "singleton class as static methods" wants, is that I instantiate a class I'm 100% certain I will only ever instantiate once. To me it seems like doing "double work", because it's all ready there. What am I missing?
What's the view on the matter? Of course it's not a life and death issue, but one might as well do a thing the right way, if the option is there :)
An example singleton classes in php:
Creating the Singleton design pattern in PHP5 : Ans 1 :
Creating the Singleton design pattern in PHP5 : Ans 2 :
Singleton is considered "bad practice".
Mainly because of this: How is testing the registry pattern or singleton hard in PHP?
Wanna read more? :
A Singleton decision diagram (source):