Singleton
A Singleton is not a computer geek who can’t get a date. Instead, a Singleton is a software design pattern allowing an application to have a variable for which there is only one instance. Every consumer of the Singleton object gets a handle to the exact same object. This technique is used in many languages such as Java, Dot Net (VB and C#, et al) and may even be implemented in JavaScript with a little effort as well as many others. In short, the pattern is language agnostic.
In some ways a static variable may perform similar to a singleton. However, a singleton provides you with more control for instantiation and destruction. It may even be used across application domain boundaries (be called from another program).
I have seen a number of ways to create a singleton object. Some are very sophisticated; others are quite simplistic. Each technique has its place and purpose.
I recently came across this blog, written by a fellow using the handle BinaryMist, on the Singleton pattern providing a great introduction to the concept and how it may be coded. If you are a software developer, you may even be asked an interview question about the Singleton pattern.
I recommend it to you in that it is an easy read. The examples are not long so you can capture the purpose quite quickly without reading pages of code. There are some links to other more lengthy dives into the concept of the Singleton as well.
I hope this is helpful to our developer readers building up their pattern skills.
Feel free to drop me a note with your comments about this or any other pattern you find helpful or would like to know more about.
Cheers,
Ben
$$SWYNK$$
Featured White Paper(s)
Top 10 Tips for Optimizing SQL Server Performance
read more)
Featured Script
getNextID – roll your own table based id-counter
Generic proc that returns the next avilable id-counter for the specified table without the possibility for concurrent users t… (read more)