Singleton Pattern
Overview
Ensure a class only has one instance, and provide a global point of access to
it.
Participants
- specify a class, which should be instantiated only once.
- this participant can not be an interface.
- specify a class with a static method to instantiate Singleton.
- this participant can not be read-only.
- this participant can not be an interface.
Parameters
-
here you specify the name of an attribute where Singleton Factory will keep a reference to
the (only) instance of Factory.
-
when selected, will create special JavaDoc links in the code between pattern participants, describing
their relationships.
-
here you can specify the name of a method for obtaining the Singleton object.
Applicability
Use the Singleton pattern when
-
there must be exactly one instance of a class, and it must be accessible to clients from a well-known access point.
-
when the sole instance should be extensible by subclassing, and clients should be able to use an extended instance without modifying their code.