O'Reilly logo

Design Patterns Explained: A New Perspective on Object-Oriented Design, Second Edition by Alan Shalloway, James R. Trott

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

Chapter 21. The Singleton Pattern and the Double-Checked Locking Pattern

Overview

This chapter continues the e-commerce case study introduced in Chapter 9, “The Strategy Pattern.”

This chapter

•   Illustrates how a factory can control the number of instances of an object that can ever exist, using the Singleton pattern.

•   Describes the key features of the Singleton pattern.

•   Introduces a variant to the Singleton called the Double-Checked Locking pattern.

•   Describes some of my experiences using the Singleton pattern in practice.

The Singleton pattern and the Double-Checked Locking pattern are very simple and very common. Both are used to ensure that only one object of a particular class is instantiated. The distinction ...

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