问题描述
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):
- More natural access syntax
- singleton lacks a name
- easier to inherit from
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.