On design patterns: When should I use the singleton?

后端 未结 20 3036
失恋的感觉
失恋的感觉 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条回答
  •  梦毁少年i
    2020-11-22 03:22

    It can be very pragmatic to configure specific infrastructure concerns as singletons or global variables. My favourite example of this is Dependency Injection frameworks that make use of singletons to act as a connection point to the framework.

    In this case you are taking a dependency on the infrastructure to simplify using the library and avoid unneeded complexity.

提交回复
热议问题