Many projects involve numerous inter-dependent components each with their own set of functions and responsibilities. In most applications, there is usually a need for a globally accessible object for storing global information. For example, login credentials for an application can be such a case. Your application can grow to many objects (perhaps thousands), however you will always have a need to check if the user is logged in or not in a simple and convenient way without affecting the local functionality of the object you are working with. Additionally, there should only be a single instance of the login credentials object since duplicating it may create inconsistencies should theuser logoff abrumptly and only the original instance is updated as such.
Here, a simple application of the Single pattern can save the day. A singleton is a globally accessible single instance object.
To apply the singleton pattern, as the name implies, you create a class Authenticate and you disallow explicit construction of the class. Additionally, you provide a property to always obtain the single instance always in existance. The following code demonstrates a Login authentication class.