What are the use of singlet classes in the design (Can contain only one instance)?

    2 answers 2

    Singleton is a copy of a class that can be only one in the whole system. Suppose the class UserService, with which will be made a request to the server for authorization / authentication. There is no need to create an instance of the UserService class each time. This class will be described as a singleton and there will be only one instance in the system (when you try to create a new instance, the result of the first creation will be returned, that is, the first and only instance).

      The answer to your question is in its wording.

      Singlet classes (or, alternatively, the Singleton pattern) are used in cases when it is necessary to provide a single “access point” to certain data or functions of the program.