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

how can u create the forms authentication?and what is the difference between forms authentication and windows authentication?

2 Answers   IBM,


What is the maximum length of textbox

1 Answers  


How can you implement encapsulation in asp.net?

6 Answers   TCS,


What are the security types in asp.net?

0 Answers  


Difference between Dataset and DataReader ?

4 Answers   Accenture, BirlaSoft, Infosys, Microsoft, Techseol,






What is cas?

0 Answers  


What are url fragments?

0 Answers  


Could u send me the answer for this question as soon as possible. Im using 'System.net.mail.mailmessage' namespace for sending a mail from my application. What should I mention in 'system.net.mail.mailmessage.to' property and What should I mention in 'system.net.mail.mailmessage.from' property.

1 Answers  


what is the dllhell? why we use the dllhell?

4 Answers  


Explain the different parts that constitute ASP.NET application?

0 Answers   B-Ways TecnoSoft,


What is the use of worker process in asp.net?

0 Answers  


Can you clarified A Web service can only be written in .NET or not?

0 Answers   Siebel,


Categories