• Post Reply Bookmark Topic Watch Topic
  • New Topic

what are the conditions to be followed in creating a singleton class or design?  RSS feed

 
senthil sen
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what are the conditions to be followed in creating a singleton class or design?
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Singleton is merely a Design Pattern. Implementations can vary greatly, especially among languages.
In Java, a Singleton is typically implemented with a public static method that maintains and returns a single instance of the class. The construction of the class outside this static method is forbidden by setting the acessibility level of the Constructor to private.
Example:

For further information on Singletons, swing by the OO, Patterns, UML and Refactoring Forum where this topic is of frequent discussion.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!