[AI] Singleton Pattern
Tech Dose of the Day
vishnuhappy at yahoo.com
Wed Jun 18 08:22:30 EDT 2008
Dosed by Vivekasundaram M – M & E Team (from MphasiS Software Services)
What is Singleton?
A design pattern is a general solution to a common problem in software design. A design pattern isn't a finished design that can be transformed directly into code; it is a description or template for how to solve a problem that can be used in many different situations.
One of these design patterns is called the Singleton can be described as, the variables and functions are locked up inside a class and access restricted to it by implementing a single point of access i.e. ensure a class has only one instance and provide a global point of access to it. It is achieved by only creating a new instance the first time it is referenced, and thereafter it simply returns the handle to the existing instance.
What is its usefulness?
Singletons are often preferred to global variables because consume less resources compared to that of global variables. The use of widely known design patterns within the context of an application is definitely a common method for tackling many problems inherent in web development.
A scenario which developers are frequently confronted with: One object is needed across an application by other objects for doing their work.
To cite a common case, a single instance of a database connection object is required by different objects within an application for it to have database connectivity within their scope. Normally, in this situation, it's best to have a single instance of the required object for accessing within the application, instead of having multiple instances of it. Singleton pattern is a solution to it.
Explore your hobbies and interests. Go to http://in.promos.yahoo.com/groups/
More information about the AccessIndia