As I already said, I like to study patterns that make common tasks easier. The Singleton pattern was the first that I got to know. It can be used when you need to ensure that some class has only one instance, providing a known method to give access to it.
I frequently use this pattern when I want to have a global configuration class in a project. This is a Config class example that I have used in one of the .NET projects I developed:
Now I can access this class from anywhere in the code by using Config.Instance(). When I call this reference for the first time, all the data will be loaded by the private constructor, called by the Instance() method, and in the subsequent calls the unique instance will always be returned.
Igor Ramadas said
Gave up? Stopped blogging??? I knew it…