如果它没有全局范围,那么只有一个实例被认为是单例的类?

时间:2014-08-26 09:04:05

标签: javascript design-patterns

我正在阅读关于单身人士的事情,并且随处可见单身人士不善,因为他们有全球范围。如果我有一个只有一个实例的类但它不能全局访问而应该作为依赖注入 - 该类仍然是单例吗?

1 个答案:

答案 0 :(得分:0)

我找到了自己问题的答案 - 引自here

When we say “Singleton” or “JVM Singleton” in this document, we mean the classic Gang of Four singleton. (We say that this singleton enforces its own “singletonness” through a static instance field). An “application singleton” on the other hand is an object which has a single instance in our application, but which does not enforce its own “singletonness.”

所以基本上他们区分了两种不同类型的单身人士。