Singleton is a design pattern where you can have only one instance of a class. Usually, when you define a class, you expect to use many instances of the class. But in some designs this doesn’t make sense.
For instance, an application may only need one reference to the file system (since there is only one file system). Or the app has a data model that should stay in sync and so you want to make sure you have only one instance of a class available.
To implement a Singleton pattern, you will need to create a special type of constructor and then only use this constructor to get a reference to the Singleton object. ...