静态类和单例模式之间的区别? [英] Difference between static class and singleton pattern?
问题描述
静态类和单例模式之间存在什么真正的(即实际的)差异?
What real (i.e. practical) difference exists between a static class and a singleton pattern?
两者都可以在不实例化的情况下被调用,只提供一个Instance和他们都不是线程安全的。有没有其他的区别?
Both can be invoked without instantiation, both provide only one "Instance" and neither of them is thread-safe. Is there any other difference?
推荐答案
真正的答案是Jon Skeet,在另一个论坛这里。
The true answer is by Jon Skeet, on another forum here.
单例允许访问单个
创建的实例 - 该实例(或
相当于对该实例的引用)
可以作为参数到其他
方法,并被视为正常的
对象。
A singleton allows access to a single created instance - that instance (or rather, a reference to that instance) can be passed as a parameter to other methods, and treated as a normal object.
静态类只允许静态
方法。 >
A static class allows only static methods.
这篇关于静态类和单例模式之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!