开发者

What are some good uses of the Singleton pattern? Is it ever acceptable? [duplicate]

开发者 https://www.devze.com 2023-02-11 00:20 出处:网络
This question already has answers h开发者_如何学Cere: Closed 11 years ago. Possible Duplicate: Singleton: How should it be used
This question already has answers h开发者_如何学Cere: Closed 11 years ago.

Possible Duplicate:

Singleton: How should it be used

I've read that singletons are bad. For instance, it makes the code hard to test. Are there any acceptable uses of singletons?


Sometimes you want one and only one connection to a database. Making your connector a singleton ensures that you will not spin up multiple connections.

0

精彩评论

暂无评论...
验证码 换一张
取 消