Singleton design pattern
Sometimes when developing big application we come across situation when the instance of a class has to be instantiated only once.
In this scenario the design pattern we follow is named as singleton pattern.
Implementing singleton pattern ensures that a class will have only one instance created and also provides a global point of access to class instance.
 | Singleton Design Pattern |
| namespace Arindam
| | 1:{
| | 2: public class ETGSingleton
| | 3: {
| | 4: private static ETGSingleton _instance;
| | 5: private int counter =0;
| | 6: private ETGSingleton()
| | 7: {
| | 8: //
| | 9: // TODO: Add constructor logic here
| | 10: //
| | 11:
| | 12:
| | 13: }
| | 14:
| | 15: public static ETGSingleton Instance
| | 16: {
| | 17: get
| | 18: {
| | 19: if (_instance == null)
| | 20: _instance = new ETGSingleton();
| | 21: return _instance;
| | 22: }
| | 23: }
| | 24: public int getCounter()
| | 25: {
| | 26: return counter++;
| | 27: }
| | 28: }
| | 29:}
| | 30: |
|
Asp.net, Ado.net, .Net Remoting, .Net
Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML