Good case for Singletons?

后端 未结 10 1600
臣服心动
臣服心动 2021-01-05 07:24

I have an application that has several classes used for storing application-wide settings (locations of resources, user settings, and such). Right now these classes are just

10条回答
  •  悲&欢浪女
    2021-01-05 08:01

    Since your class is holding global settings, a pro for a singleton could be that you have more control about creation of the singleton. You could read a configuration file during object creation.

    In other cases if methods are static there would be no benefit like in javas Math class which has only static members.

    A more obvious need for singletons is when you implement factories as singletons, because you can interchange different implementations of this factory.

提交回复
热议问题