I have a little problem understanding the idea behind a singleton. Ok, I understand that the main advantage of a singleton is that there is always one copy of the object of this class (or isn't it?). How is singleton better then normal class?
This question is based on the application I develop with the other fellow. He insists that, for example, database abstraction class would be defined as singleton. He points out that:
1. one instance of a class is faster
2. passing values by reference (as in singleton) is quicker than making a copy
3. he's done some timing and application run faster with singleton version.
Well my replies are:
1. the class is defined and global object is created within the same included file with include_once - so there would be one object anyway, independent of in how many places it is included this way
2. PHP5 passes returned values by reference by default, so having a reference returned by ::getInstance() or a global variable returned by new operator is the same thing, or isn't it?
3. that one I can't check, but it might just as well be a psychological difference
So what do you think, is it worth to change all the classes, whose objects are supposed to be unique, to singletons? Not that it needs a lot of work, but is it worth the fuzz?