I might live with that. So what are the main pros using singletons?
- Is there performance gain or memory savings or something like that?
For all intents and purposes, no. Especially since you are in the web
environment, application runtime is extremely short (on the order of the
length of a single request). At the end of every request, memory and
resources are unloaded (this is what is called as a shared-nothing
architecture).
- Code syntax benefits?
You get a single name based container for free (a singleton is basically
both a factory and a registry). Of course, this has to line up with
your application goals, and/or your libraries overall code perspective.
- Something else?
If you are gonna use them, especially in a library, practice good
developer citizenship. If you write a getInstance() method, also
remember to write a resetInstance() method. Any stateful information
that is statically tracked by the class, should be able to be reset when
asked to.
-ralph