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

Testing the Singleton Pattern

The Singleton pattern guarantees uniform and controlled access to a unique instance of an object.2 It acts as the object-oriented stand-in for a global variable in the cases in which such is warranted. In its purest use, it corresponds to a real and unique physical resource. It is often used to represent something that is unique to the application, such as an entry point to a remote service or an application registry.

2. Do not confuse the Singleton pattern with the broader concept of a singleton object, an object of which only one exists. The Singleton pattern is one way to ensure you have a singleton object, but there are other reasonable approaches.

There are several ways to implement singletons. A typical implementation ...

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