Friday, September 10, 2010

What is difference between Singleton pattern and static class

Both can be invoked without instantiation, both provide only with one "instance" and neither of them is threadsafe.

Usually both should be implemented to be thread-safe.

The big difference between a singleton and a bunch of static methods is that singletons can implement interfaces (or derive from useful base classes, although that's less common IME), so you can pass around the singleton as if it were "just another" implementation.

Advantages of singletons



Singletons preserve the conventional class approach, and don't require that you use the static keyword everywhere. They may be more demanding to implement at first, but will greatly simplify the architecture of your program. Unlike static classes, we can use singletons as parameters or objects.

Solution by:

Rajesh Rolen

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates