Purpose of singletons in programming

后端 未结 9 1708
傲寒
傲寒 2020-12-08 01:49

This is admittedly a rather loose question. My current understanding of singletons is that they are a class that you set up in such a way that only one instance is ever crea

9条回答
  •  感动是毒
    2020-12-08 02:33

    1. Singleton is a very useful replacement of global variables, used all across the code.
    2. Singletons are usually not "new"ed or "delete"d, they tend to be initialized on first use and deleted along with program scope
    3. Singletons perfectly match for wrapping logging, configuration and other hardware-interfacing classes.

提交回复
热议问题