Singleton Intent
There are really two purposes rolled into a single class for any given implementation of a singleton. The first purpose is clearly the implementation of the Singleton pattern characteristics. The second is the function of the class itself: the behaviors associated with the class modeling the singular resource.
Ordinarily, if we found such a clear duality of purpose in a single class, we would refactor it to separate the concerns. However, the singleton nature suggests that the separate intents live in the same class. The language issues around the behavior of class variables in inheritance hierarchies in most languages prohibit refactoring the singleton nature into a superclass without adding the complexity of a registry. Refactoring ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access