
Design Patterns - Generic Singleton Pattern
Originally published on my old blog at cumps.be on July 15, 2008.
A little follow-up from yesterday’s Singleton Pattern, where I asked for some help on how you would approach a generic singleton.
With the help of Andrew Stevenson and ExNihilo, we came up with the following Generic Singleton Pattern:

Using Reflection, the private constructor is called to create an instance of the class.
Whenever a Singleton is needed now, the only thing to do is to inherit from Singleton<T>, pass in the class itself as T, and make the constructor private.
I’ve updated yesterday’s solution to contain this new code as well; have a look.
You May Also Like

Design Patterns - Command Pattern
The Command Pattern: UI buttons that run commands without knowing about game units, with undo for the last action.

Design Patterns - Singleton Pattern
The Singleton Pattern: a single GraphicsCard instance, why the simple version isn't thread-safe, and a lazy, thread-safe version with a nested class.

Design Patterns - Abstract Factory Pattern
The Abstract Factory Pattern: one GameUnit class per unit type, configured per faction by a factory passed in at runtime, and how it differs from Factory Method.



