问题描述
不是所有静态成员/方法的类都是一种单例设计模式?有没有什么缺点,特别是有这样的类?详细的解释将有所帮助。
Isn't a class with all static members/methods a kind of singleton design pattern? Is there any disadvantage in particular of having such classes? A detailed explanation would help.
推荐答案
这种类被称为 - 它与单身人士有所不同。
This kind of class is known as a monostate - it is somewhat different from a singleton.
为什么使用单体而不是单身?在他们的原始论文在模式上,贝尔&克劳福德提出三个理由(由我解释):
Why use a monostate rather than a singleton? In their original paper on the pattern, Bell & Crawford suggest three reasonns (paraphrased by me):
- 更自然的访问语法
- singleton缺少
- 更容易继承自
我必须承认,我没有找到任何这些特别引人注目。另一方面,单身人士绝对不会比单身人士更糟糕。
I must admit, I don't find any of these particularly compelling. On the other hand, the monostate is definitely no worse than the singleton.
这篇关于静态类和单例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!