问题描述
此问题一般来说,单身人士是否被认为是有害的。我只是想从你的经验中知道,单身人士似乎运作良好的一些具体情况。
This question is not about whether or not singletons are "considered harmful" in general. I just want to know, from your experience, what are some SPECIFIC SITUATIONS in which singletons seem to work well.
编辑:
如果你想讨论一般 的单身人士的适当性和/或邪恶,那么有一个潜在的问题:,
Please, if you want to discuss the appropriateness and/or evilness of singletons in general, there are aleady exising questions: 137975, 11831
糟糕!我刚刚发现我的问题已经在这里被问到:
Oops! I've just discovered that my question has already been asked here: On Design Patterns: When to use the Singleton?
推荐答案
我们基本上使用它们两件事情:记录和配置。两者都假定应用程序具有中央配置和中央日志文件,并不总是有效,但在我们的大多数代码中。我们也有时会使用它们来确定某些工厂类或缓存类,以确保我们不会重复关键的元数据。
We basically use them for two things: logging, and configuration. Both assume that the app has a central config and a central logfile, not always valid but in most of our code it is. We also use them on occasion for certain factory classes or cache classes we want to make sure we're not duplicating key metadata.
这篇关于单身人士的具体合法用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!