You are not logged in.

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

1

Monday, October 26th 2009, 7:02pm

[Design pattern] Singleton

Hi @All

with Jabaco you are able to program with the whole bunch of OOP-features.

How to make a singleton in Jabaco?

For example the ErrObject in VB6 is a real singleton. It refuses you to make another instance of it.

Class: MyFirstSingleton

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Private myDescription As String
Private Static myInstance As MyFirstSingleton = Nothing
Private Sub MyFirstSingleton()
myDescription = "Hide the standard constructor by making it private." & vbCrLf & _
                "Create a private static field MySingletonClass myInstance" & vbCrLf & _
                "Create a public function getInstance that returns myInstance"
End Sub
Public Static Function getInstance() As MyFirstSingleton
   If myInstance = Nothing Then myInstance = New MyFirstSingleton
   getInstance = myInstance
End Function
Public Function getDescription() As String
   getDescription = myDescription
End Function


little example how to use it:

Jabaco Source

1
2
3
4
5
6
7
Public Sub Command1_Click()
   
   Dim s As MyFirstSingleton = MyFirstSingleton.getInstance
   
   MsgBox s.getDescription
   
End Sub


this one is really easy :)

in VB and in Jabaco of course you also could use a Module.



regards

OlimilO

Rate this thread
WoltLab Burning Board