Implementing the singleton pattern in Java

前端 未结 6 731
一生所求
一生所求 2020-11-30 06:09

Can anyone provide an example of a singleton pattern and explain why they are necessary?

6条回答
  •  春和景丽
    2020-11-30 06:41

    danben has a pretty good summary of what a singleton is, so I won't rehash it.

    As far as uses go, singletons are often thinly veiled implementations of global variables (which is a bad idea). They can be useful for things like message routers or manager classes (among other things).

提交回复
热议问题