© Dmitri Nesteruk 2018
Dmitri NesterukDesign Patterns in Modern C++https://doi.org/10.1007/978-1-4842-3603-1_5

5. Singleton

Dmitri Nesteruk1 
(1)
St. Petersburg, Russia
 

The Singleton is the most hated design pattern in the (rather limited) history of design patterns. Just stating that, however, doesn’t mean you shouldn’t use the singleton: a toilet brush is not the most pleasant device either, but sometimes it’s simply necessary.

The Singleton design pattern grew out of a very simple idea that you should only have one instance of a particular component in your application. For example, a component that loads a database into memory and offers a read-only interface is a prime candidate for a Singleton, since it really doesn’t make sense to waste memory ...

Get Design Patterns in Modern C++: Reusable Approaches for Object-Oriented Software Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.