Singleton or Class method ?
This topic might too old for some of you but I always was reminded to this issue when I was going to write some method just do some algorithms - take inputs, processing, return output.
We will find many discussions on this issue if we do googling. Below this are what I conclude those discussions for myself.
- Singleton provides typing. You can subclassing or passing it around whatever you can do to an object-oriented instance you can do to Singleton object.
- Singleton provides state which a lot of you may think it is disgusting.
- Singleton provides lazy-initialization. You have not to have it on your memory until you are really want it.
- You can have many instances of Singleton-type. Also can limit number of them. While you can not do this with Class method.