What are the real world applications of the singleton pattern?

后端 未结 10 533
南旧
南旧 2021-02-01 07:22

Duplicate

On design patterns: When should I use the singleton?

class Singleton
{
    private static Singleton instance;

    private Singleton() {}

             


        
10条回答
  •  时光说笑
    2021-02-01 07:58

    One way I've used a singleton is to implement a "main controller" object for an application. This was a bit like the Application object you get with VBA.

    This object performed various startup and shutdown tasks. It also provided access to application-wide settings and services. This included values of command-line parameters and the logging service, among others.

提交回复
热议问题