How can we implement singleton pattern in .NET
How can we implement singleton pattern in .NET?
Singleton pattern mainly focuses on having one and only one instance of the object running.
Example a windows directory service which has multiple entries but you can only have
single instance of it through out the network.
Note:- May of developers would jump to a conclusion saying using the STATIC keyword we can have a single instance of object. But thats not the real case there is something more that has to be done. But please note we can not define a class as STATIC, so this will not serve our actual purpose of implementing singleton pattern.
Following are the three steps needed to implement singleton pattern in .NET:-
ã First create your class with static members.
Public class ClsStaticClass
Private shared objCustomer as clsCustomer
This ensures that there is actually only one Customer object throughout the project.
ã Second define a private constructor to your class.
Note: - defining a private constructor to class does not allow a client to create objects directly.
ã Finally provide a static method to get access to your singleton object.
2007-10-24, 6483👍, 0💬
How To Return Top 5 Rows? - MySQL FAQs - SQL SELECT Statements with JOIN and Subqueries If you want ...
I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, ...
How Oracle Handles Dead Locks? - Oracle DBA FAQ - Understanding SQL Transaction Management Oracle se...
What Happens If One Row Has Missing Columns? - XHTML 1.0 Tutorials - Understanding Tables and Table ...
Can Two Forms Be Nested? - XHTML 1.0 Tutorials - Understanding Forms and Input Fields Can two forms ...