The Singleton Pattern: Java Design Patterns and Architecture, Part 10

The singleton pattern allows you to have a single global instance of a class, available from any part of your program. This can make your code hard to follow if you're not careful, so you should use singleton cautiously, decide carefully where to access your global object and, some say, try hard to not use it at all. Nevertheless, used judiciously it can help to avoid excessive parameter passing and can usefully prevent you creating multiple instance of classes that shouldn't have multiple instances, for instance classes that encapsulate database connections or graphics handles.



Source Code


DesignPatterns10 - Singleton.zip

Next ...


Beans: Java Design Patterns and Architecture, Part 11