Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic