From the course: Design Patterns: Creational

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

The Singleton pattern

The Singleton pattern

From the course: Design Patterns: Creational

Start my 1-month free trial

The Singleton pattern

- [Narrator] The last creational pattern from the Gang of Four catalog is the singleton pattern. This is a specialized creational pattern that is designed to ensure you have only one instance of a class. In fact, that's exactly what the intent of the pattern says. The full intent of the pattern is to ensure that a class has only one instance and to provide a global point of access to that instance, meaning that other objects in your code can easily get access to that single instance. Now, you might be asking yourself, "Do we really need a pattern "to ensure there's only one instance of a class?" Remember that patterns come from the experience of other developers, and so it's likely the case that early object-oriented programmers, but found themselves with bugs in the system caused by multiple instances. The pattern is here for a reason. Let's say you have a venue ticketing system, and you want to make absolutely sure…

Contents