The Artima Developer Community
Sponsored Link

Legacy Design Forum
Designing with Interfaces



This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Singleton Pattern -- Only One Instance Allowed

Posted by Bill Venners on April 21, 2000 at 2:46 PM

> What is meant by Singleton?
> Explain with sample code.

A Singleton is a design pattern described in the Gang of Four
Design Patterns book. It just means a class that allows only
one instance of itself to ever be created.

I have an example of a singleton in Java in my handout for one
of the modules of my Object Design Workshop:

Search for "class Has0State" in that file. The Has0State class
is an example of the singleton pattern because it only allows
one instance of class Has0State. For more info, check out the
Design Patterns book. I have more info on this book on the
Recommended Design Books page at:

It's the blue and white book in the picture at the top left of
that page.



Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us