Singleton
Overview
Ensure a class only has one instance, and provide a global point of access to
it. 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.
Participants
Singleton
Specify a class, which should be instantiated only once.
- This participant can not be an interface.
Singleton Factory
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
instanceField
In the "instanceField" attribute you can specify the name of an attribute
where Singleton Factory will keep a reference to the (only) instance of
Factory.
instanceMethod
In the "Instance method" field you can specify the name of a method for
obtaining the Singleton object.