Singleton Pattern is probably the most well known of all design patterns. And it is also one of the most simple. The requirement for this pattern arises when you need to share a single instance of a class across your whole application. The download link for this sample project is available at the bottom.
The implementation of the Singleton pattern consists of:
- A Class with a private field pointing to its own instance. This can be initialised on the field itself or in the Instance Getter.
- Private constructor. There should not be any public constructors to this class.
- A Getter property for the Instance.
Why not just use a Static Class?
The advantage of using a normal class is that it can inherit from another class or implement an interface. And also this class can be passed as a parameter in a method.
Download Sample Code