单身人士的具体合法用途是什么? [英] What are some specific legitimate uses for singletons?

查看:170
本文介绍了单身人士的具体合法用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

设计模式:何时使用单身人士?

此问题一般来说,单身人士是否被认为是有害的。我只是想从你的经验中知道,单身人士似乎运作良好的一些具体情况

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.

编辑:
如果你想讨论一般 的单身人士的适当性和/或邪恶,那么有一个潜在的问题: 137975 11831

Please, if you want to discuss the appropriateness and/or evilness of singletons in general, there are aleady exising questions: 137975, 11831

糟糕!我刚刚发现我的问题已经在这里被问到:设计模式:何时使用Singleton?

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.

这篇关于单身人士的具体合法用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆