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 |
can u debug application programatically? if yes how?
How we can force all the validation controls to run?
How can you implement the postback property of an asp.net control?
How will you do windows authentication and what is the namespace? If a user is logged under integrated windows authentication mode, but he is still not able to logon, what might be the possible cause for this? In ASP.Net application how do you find the name of the logged in person under windows authentication?
Explain the different types of assemblies?
What is difference between view and partial view?
What I need to create and run an asp.net application?
Question asked by one of interviewer in panal is given below: We have 2 user control on same page ,1st user control contains textbox and a button while 2nd user control have label. when ever we click on button click of 1st custom control button the value of the textBox will get updated into Label of 2nd custom control. How to do this.Your help will be appreciated.
What is session object? Describe in detail.
How does asp.net page work?
How to create a db connection at one place/page so that we can use that connection for all pages/forms/windows.what r the steps ned to be performed if question not clear,let me know
What is the life-span of the items in the viewstate?