Skip to main content

Posts

Showing posts from April, 2014

Singleton Design Pattern and different ways to implement it in C#

The singleton pattern is one of the best-known patterns in software engineering. In a singleton pattern, we ensure that the class has only one instance and we provide a simple and global point of access to this object. This is useful when we require exactly one object of a class to perform our operations. Singleton classes don't allow any parameters to be specified when creating the instance because a second request for an instance but with a different parameter could be problematic. In this article, I'll provide you with a real-time example, a Comparison of Singleton with Static class, a UML class diagram of Singleton, and then the implementation of Singleton in various ways. Real-time example: The practical implementation of the Singleton design pattern can be seen in various applications used by us. Take the example of Microsoft word, there is only one instance of the word application active at a time even though the user opened multiple documents at a time. And all the req