June 2003
Intermediate to advanced
800 pages
34h 20m
English
You want to ensure that only one copy of a class can be instantiated at once and provide global access to this instance.
Add a private constructor to the class and a shared variable that holds the singleton instance.
The syntax for creating a singleton in languages that target .NET is quite a bit simpler than in many other languages, due to the way the common language runtime operates. The basic pattern is to add a shared variable that returns an instance of the singleton class, as shown here:
Public Class MySingleton Private Sub New() ' A private constructor ensures this class can't be created directly, ' except by code in this class. End Sub ' This shared member is available even without an instance ...
Read now
Unlock full access