Skip to main content
2 of 2
+singleton drawbacks
palacsint
  • 29.9k
  • 9
  • 81
  • 156
private static int i = 0;

Are you sure that i should be static? If it's static there isn't too much sense of the Counter instance = new Counter() instance and the Next and the Reset methods also could be static.

Anyway, I'd use a longer variable name, like nextValue for better readability.

Furthermore, consider the drawbacks of the Singleton pattern:

This pattern makes unit testing far more difficult, as it introduces global state into an application.

More on Wikipedia.

palacsint
  • 29.9k
  • 9
  • 81
  • 156