|Home||Back to Index|
It’s amazing what you can do with generics in C#. Here’s one way to implement a generic Singleton:
If you’re wondering about the need for an empty static constructor, see http://www.yoda.arachsys.com/csharp/singleton.html.
Non-abstract descendants should be sealed:
One downside is that you do need a public constructor (implicit in the example), so it is possible for clients to bypass the Singleton instance.