Recognizing Singleton
Unique objects are not uncommon. In fact, most objects in an application bear a unique responsibility; why would you create two objects with identical responsibilities? Similarly, nearly every class has a unique role. Why would you develop the same class twice? On the other hand, singleton classes—classes that allow only a single instance—are relatively rare. The fact that an object or a class is unique does not imply that the SINGLETON pattern is at work. Consider the classes in Figure 8.1.
Figure 8.1. Which classes appear to apply Singleton?
|
Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.