Implement Singleton
Singleton…have you ever hear it? Yes, it’s kind of design pattern.
Actually I have just apply it in my assignment and successfully run as
I wish :). Do you know design pattern? Design pattern is kind of
patterns that usually happen when you develop object-oriented
programming. It’s kind of an algorith, not an implementation code.
Singleton is one of them, the functionality is to prevent class was
defined more than once. In case, I defined a new object form class a,
it will allocate memory for class a object. In others time, I’d like to
create a new one in another screen, it will allocate memory for class a
object too. What if I create object from class a in a double double ?
So pure if I become the memory
Below code is an implementation of singleton in VB .Net.
#Region “Design Pattern Singleton“
Private Shared instance_Dgr As cDigram
Protected Sub New()
End Sub
Public Shared Function getInstance_Digram() As cDigram
If instance_Dgr Is Nothing Then
instance_Dgr = New cDigram
End If
Return instance_Dgr
End Function
#End Region
In your associated class, you could put your code as below to instantiate a new object.
Private oDigram as cDigram
oDigram = cDigram.getInstance_Digram
I’m happy finally I could implement it