Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Can we make activex dll also ti execute in some process as that of client ? How can we do?

4747


What are strong names?

1040


Can a master page have more than one contentplaceholder?

968


Why do we use sessions?

1001


Explain what is an abstract class?

1024


What is an asp.net validator? And, mention its types.

1025


Which method has beenintroduced in asp.net 4.0 to redirect a page permanently?

967


What are server activated objects?

1169


What is the difference between server-side scripting and client-side scripting?

994


What is web router?

924


What are the new features implemented in ASP.NET?

1086


What is redirecting behavior?

967


What is client side state management?

965


What is the extension of master page in asp.net?

978


How do we access view state value of this page in the next page?

1001