static class and singleton


Question

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.

1
12
4/6/2009 10:22:29 AM

Accepted Answer

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.

17
4/7/2009 5:23:39 AM

Robert C. Martin wrote an article some times ago about the differences between the mono state pattern and the singleton pattern.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon