Friday, December 5, 2008

Singleton Pattern vs. Static Class

refers: http://dotnetperls.com/Content/Singleton-Static.aspx

When I heard singleton pattern, the first thing came in my mind is: not a big deal, it is just a static class.

But actually, you won't want to use static class to implement the singleton pattern, if you read the referred article.
Basically, using a non-static class with private constructor and a static Instance are much better than static class:
1) Static class cannot implement interfaces, also it cannot be inheritted by other classes.
2) Static class cannot be passed as an object to a method, but SingletonClass.Instance definitely can.

No comments: