Singleton

The Singleton pattern is a type of class that can have only one instance. Every time you try create to create an instance of a Singleton, you don’t actually get a new instance—you are really getting only a reference to a single instance. For example, the PacMan class could be implemented as a Singleton. You might try to create an instance of PacMan in several different places in your code, but you really want only one PacMan. If the PacMan object has already been created, you don’t actually want to create a second PacMan; you really just want a reference to the existing PacMan.

Get Learning to Program 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.