I'm sorry for pause in writing new posts about design patterns.
So, today I'm going to write a post about the most popular and well-known design pattern - Singleton.
The essence of Singleton is to provide :
- exactly one instance of class across the system;
- simple access to it.
The implementation of Singleton based on creation a class with a method(or property in .NET) that creates an instance of this class if one doesn't exists yet. The constructor of class must be private to prevent other ways of initialization. Also Singleton must be carefully used in multi-threaded applications because in one point of time, the two threads may create two different instances (which violates singleton pattern).