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

Explain the difference between panel and groupbox classes using .net?

1 Answers  


version information is mentioned in which file

3 Answers   AG Technologies,


what are the application layers for a distribute application?

0 Answers   Mind Tree,


What are the new data controls in asp.net 2.0?

1 Answers  


Please briefly explain the usage of global.asax?

1 Answers  


What is postback request?

1 Answers  


Can a user browsing my Web site read my Web.config or Global.asax files ?

1 Answers  


What is the namespace used to store the information about the user?s locale?

1 Answers   NeoSoft, Siebel,


how to add cliet side event to server side? and how to register client script to sever side? wt difference these two

3 Answers   PSI Data Systems,


what is view state and its use

10 Answers   DELL, Efextra, HCL,


benefits of migration from asp to asp.net hi frnds, i have to give presentation to a client about how useful would be migrating their project from asp to asp.net .plz give me some points which i should incorporate in my ppt thanks

1 Answers  


Describe Segmentation With Paging?

1 Answers   MaxSolPro,


Categories