On design patterns: When should I use the singleton?

后端 未结 20 3500
失恋的感觉
失恋的感觉 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:43

    You can use Singleton when implementing the State pattern (in the manner shown in the GoF book). This is because the concrete State classes have no state of their own, and perform their actions in terms of a context class.

    You can also make Abstract Factory a singleton.

提交回复
热议问题