Singleton Design pattern?How do you achieve it?
Answers were Sorted based on User's Feedback
Answer / mithun kanungo
We Can Achieve Singleton Design Pattern By restricting Other
Class To Make Object of the class By Using Constructor
instead we can Use A Static Method to get hold of the
Instance of the class , And By making our Constructor
private we can Restrict other classes to make Instance of
the Class , So that All other Classes use the same static
method to make only one instance of the class.
| Is This Answer Correct ? | 6 Yes | 0 No |
Answer / shijas
Singleton design pattern we can implement using Static key
word that means only one instance.All the instances are
coming from the same memory location.
| Is This Answer Correct ? | 3 Yes | 0 No |
Singleton design pattern can be achieved by following implementation:
1) Make class public
2) Static method to generate the instance of class(calling this method we can get the instance of a class if already a instance is generated we will get the same instance)
3) Private Constructor (so that no other class can generate the instance of singleton class)
Example::
class Class1
{
private static Class1 classInstance;
private IList<int> list = new List<int>();
private Class1()
{
if (list == null)
{
list = new List<int>();
}
}
public static void GetInstance()
{
if (classInstance == null)
{
classInstance = new Class1();
}
}
}
| Is This Answer Correct ? | 1 Yes | 0 No |
What is web.config. How many web.config files can be allowed to use in an application?
6 Answers Accenture, HCL, InterGraph, iSoft,
how to add cliet side event to server side? and how to register client script to sever side? wt difference these two
3. What goals do you have in your career?
What is cyclomatic complexity and why is it important?
which event in global.asx that fires for every request of same user?
5. What three Specific Job Positions do you target from Swatz Oils GROUP U.K?
In asp.net, how can you validate drop down box?
Types of configuration files and their differences ?
How To Generate ConnectionString By Using Notepad??
What is true about application service provider?
What are the versions of garbage collection?
What is mvc structure? given example? How to show gridview control from business components and using class object arrays?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)