Page 1 of 3 Prev - Next >>
DESIGN PATTERNS Singleton Rationale and Motivation The singleton pattern applies to the many situations in which there needs to be a single instance of a class, a single object. It is often left up to the programmer to insure that the important consideration in implementing this pattern is how to make this single instance easily accessible by many other objects. Advantages What are the advantages to using this pattern? Single instance is controlled absolutely. When implemented as the pattern recommends, the class will have direct control over how many instances can be created. This is in contrast to making the programmer responsible for insuring that there is only one instance. This pattern is easily extensible to allow a controlled number of "singleton" objects to be created. The most important modification needed to accomplish this change is in the operator that has control over access to the instances. In this case, the Instance() function would need to be changed.
|