On design patterns: When should I use the singleton?

后端 未结 20 3346
失恋的感觉
失恋的感觉 2020-11-22 02:45

The glorified global variable - becomes a gloried global class. Some say breaking object-oriented design.

Give me scenarios, other than the good old logger where it

20条回答
  •  春和景丽
    2020-11-22 03:30

    You use a singleton when you need to manage a shared resource. For instance a printer spooler. Your application should only have a single instance of the spooler in order to avoid conflicting request for the same resource.

    Or a database connection or a file manager etc.

提交回复
热议问题