Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Realtime exa. of Singleton class???

 
jone wars
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need realtime example of singleton class.
when should we go for singleton class???
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost never. You could say enums are singletons so that might be the only good example of use. Singletons are difficult to test, easy to missuse and tent to end up in a "Oh actually i need more than one" situation.
 
Winston Gutkowski
Bartender
Pie
Posts: 10236
58
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jone wars wrote:i need realtime example of singleton class.
when should we go for singleton class???

I agree with everything Manuel said - almost never - however, one well-known use of singletons is for a logger (ie, the encapsulation of a logging service).

For more information, I suggest you read this.

Winston
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic