Was this helpful?
0 votes
|
Let me start with a little secret: having asked what the difference is between a static class and a singleton, I pretty much know the answer. A static class is a class whereas a singleton is an object (i.e. a class instance). Both are 'singletons': there can be only one static class (for that class) and there can only be one instance of a Singleton (which is enforced by the members of the Singleton). So far so good, but here is the real question: Why would anyone write a Singleton, when a class is so much easier? Static classes are globally visible and there is just one in the entire application. Simple. Yes, Singletons can implement an interface, but I have not need for an interface. And yes, classes live on the stack whereas singletons live on the heap, but I don't care about either (until I am missing something?). So, again, why would anyone write a Singleton? |
asked | Apr 12, 2016 |
viewed | 195 times |
active | Apr 12, 2016 |