/*
Author: Jiangong SUN
*/
Last update: 29/05/2013, 30/05/2013
There are 4 categories of design patterns called Gang of Four (GoF):
- Creational patterns
- Structural patterns
- Behavior patterns
- Concurrency patterns
Singleton is a creational pattern.
Double-checked locking is a concurrency pattern.
Lazy initialization is a a creational pattern.
Singleton is a design pattern used to limit one class to have just only 1 instance.
Here is an example of basic Singleton:
Here is an example about Double-check locking singleton:
volatile: ensures that one thread retrieves the most up-to-date value written by another thread.
Here is another Lazy initialization singleton example:
Call the methods inside the singleton classes.
The two implementation of singleton works, and you can choose the ideal one with your special requirements.
I hope this post does help to you. Enjoy coding!
Refrence:
http://csharpindepth.com/Articles/General/Singleton.aspx
http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29#Classification_and_list