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

What is a Managed Data?

4 Answers   HCL,


i wand basic interview based questions in asp.net and vb.net

0 Answers   Legio Infotech,


What is difference cookie and session?

0 Answers  


With out Web.config can we executes the application?

10 Answers   Valtech,


What is the Difference B/W Finalize() and Dispose() in .Net?

12 Answers   HCL, IBM,






Your ASP.NET application displays sales data on a page. You want to improve performance by holding the page in memory on the server for one hour. You want to ensure that the page is flushed from memory after one hour, and that the page is re-created when the next request for the page is received. What should you do? A . Initialize a new instance of the Cache class in the Application.Start event handler. B . Initialize a new instance of the Timer class in the Page.Load event handler. C . Set the Duration attribute of the OutputCache directive in the page. D . In the Web.config file, set the timeout attribute of the sessionState element.

5 Answers   ADITI, Syntax Softtech,


What is an iHTTPModule, and explain its implementation with its limitations?

1 Answers   Siebel,


To load your generated dataset with data which method do you invoke?

0 Answers   Siebel,


What?s a bubbled event?

6 Answers   Visual Soft,


You create an assembly to access data in a relational database. This assembly will be used by several ASP.NET applications on your Web server. You need to ensure that all your applications can access the assembly. Which two actions should you take (Each Answer: presents part of the solution.)? (Choose two) A . Run the Assembly Registration tool (Regasm.exe). B . Run the String Name tool (Sn.exe). C . Run the Installer tool (Intallutil.exe). D . Run the Global Assembly Cache tool (Gacutil.exe).

6 Answers   CPCL, Syntax Softtech,


When you use Ajax controls in the ASP.NET application?

0 Answers   Viscus Infotech,


What are Session states available and its Uses?

0 Answers   CTS, iLogic,


Categories