Chapter 11. The Singleton Pattern

The Singleton pattern is grouped with the other Creational patterns, although to some extent it is a pattern that limits, rather than promotes, the creation of classes. Specifically, the Singleton assures that there is one and only one instance of a class and provides a global point of access to it. There are any number of cases in programming where you need to make sure that there can be only one instance of a class. For example, your system can have only one window manager or print spooler, or a single point of access to a database engine. Your PC might have several serial ports but there can only be one instance of “COM1.”

Creating Singleton Using a Static Method

The easiest way to make a class that can ...

Get C# Design Patterns: A Tutorial 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.