Singleton (Chapter 8)

SOLUTION 8.1To prevent other developers from instantiating your class, create a single constructor with private visibility. Note that if you create other, nonprivate constructors or create no constructors at all, other developers will likely be able to reinstantiate your class.
SOLUTION 8.2As Design Patterns says, “You might not have enough information to instantiate every singleton at static initialization time. A singleton might require values that are computed later in the program's execution” (p. 130). When a Factory singleton is born, for example, it might have to establish connections with machine drivers, to set up planners, and to initialize a simulation of itself.
SOLUTION 8.3Your solution should eliminate the possibility ...

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.