O'Reilly logo

Quality Code: Software Testing Principles, Practices, and Patterns by Stephen Vance

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required