Singleton Design pattern?How do you achieve it?
Answer Posted / 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 View All Answers
Can we make activex dll also ti execute in some process as that of client ? How can we do?
What are strong names?
Can a master page have more than one contentplaceholder?
Why do we use sessions?
Explain what is an abstract class?
What is an asp.net validator? And, mention its types.
Which method has beenintroduced in asp.net 4.0 to redirect a page permanently?
What are server activated objects?
What is the difference between server-side scripting and client-side scripting?
What is web router?
What are the new features implemented in ASP.NET?
What is redirecting behavior?
What is client side state management?
What is the extension of master page in asp.net?
How do we access view state value of this page in the next page?