Categories:
.NET (357)
C (330)
C++ (184)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (2)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can we implement singleton pattern in .NET
How can we implement singleton pattern in .NET?
✍: Guest
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 that’s 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
End class
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, 8086👍, 0💬
Popular Posts:
Advantages of a macro over a function? Macro gets to see the Compilation environment, so it can expa...
.NET INTERVIEW QUESTIONS - How to prevent my .NET DLL to be decompiled? By design .NET embeds rich M...
Can one execute dynamic SQL from Forms? Yes, use the FORMS_DDL built-in or call the DBMS_SQL databas...
How do you locate the first X in a string txt? A) txt.find('X'); B) txt.locate('X'); C) txt.indexOf(...
What is Traceability Matrix? Traceability Matrix is one of the document will prepare by QA.To make s...