Singleton Design pattern?How do you achieve it?

Answers were Sorted based on User's Feedback



Singleton Design pattern?How do you achieve it?..

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

Singleton Design pattern?How do you achieve it?..

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?How do you achieve it?..

Answer / sudhir sheoran

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

Post New Answer

More ASP.NET Interview Questions

Do cookies store passwords?

0 Answers  


what is the MSIL assembler do?

1 Answers  


what is difference between User Control,Custom Contro1,Web server control and template controls

1 Answers  


Which is the best institute in Hyderabad/Secunderabad/Andhra Pradesh to learn DotNet?

0 Answers  


Name two properties common in every validation control?

1 Answers  






difference between <connectionstring> <Appsetting>

6 Answers   VebTel,


when using personlization, how do you access over setting at runtime?

1 Answers  


Usage of web.config?

2 Answers   Microsoft,


What are merge modules?

0 Answers  


What is difference between Fragment Caching and Page Caching in ASP.NET?

0 Answers   PUCIT,


I have got less marks in bsc it So how to get interview.tell me

1 Answers  


Less than one page, how many windows will you be able to maintain?

0 Answers   Atos Origin,


Categories