0

I read the answer about static vs singelton, however, i specifically look for concrete examples of when should i use a static class instead of a singelton. As it seems at the moment, singelton should always be used.

Thanks.

Edwin Stoteler
  • 1,218
  • 1
  • 10
  • 25
user1413824
  • 659
  • 1
  • 8
  • 15

1 Answers1

0

I suggest you to read the book "Design patterns - Elements of Reusable Object-Oriented Software" by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides (http://en.wikipedia.org/wiki/Design_Patterns).

Among the differences, a singleton can be be lazily constructed, requiring no memory or resources until needed.

Claudio
  • 10,614
  • 4
  • 31
  • 71
  • But a static need not be constructed at all. – weston Jun 03 '13 at 08:54
  • @weston it does. There are static constructors for example. – Myrtle Jun 03 '13 at 09:03
  • @Aphelion Sure, but 1. they don't construct anything unless you call `new` statements inside them and 2. they are lazy (c# at least), being called on the first time the class is used, which is precisely their argument for using singleton over static. – weston Jun 03 '13 at 09:11