05.01.2012
OOP in LotusScript: Overloading Constructors the LotusScript Way
>>Author: Thomas Bahn
>>Ort: Antalya
URL: http://www.assono.de/blog/d6plinks/OOP-in-LotusScript-Overloading-Constructors-the-LotusScript-WayCategory: OOP, LotusScript, Entwicklung
To pass a "list" of parameters is one way to gain more power in creating the constructor.
But especially, when all is just about one parameter this way results in too much overhead. To use a Variant and an "object separator" is leaner and more elegant.
Lets use the constructor of the class OpenGeoDBRecord
as an example. Objects of this class should be initialized either with
a list, an array, a NotesDocument, a NotesViewEntry or just devoid with
default values:
Private Class OpenGeoDBRecord
Public Sub New(source As Variant)
Dim openGeoDoc As NotesDocument
Dim openGeoEntry As NotesViewEntry
If TypeName(source) = "VARIANT LIST" Then
Call ReadFromList(source)
ElseIf TypeName(source) = "STRING( )" Then
Call ReadFromArray(source)
ElseIf source Is Nothing Then
' initialize with default values...
ElseIf source IsA "NotesDocument" Then
Set openGeoDoc = source
Call ReadFromDoc(openGeoDoc)
ElseIf source IsA "NotesViewEntry" Then
Set openGeoEntry = source
Call ReadFromViewEntry(openGeoEntry)
End If
End Sub ' OpenGeoDBRecord.New
Public Sub ReadFromList(paramList As Variant)
'/**
' * reads data from a list with the parameter names as keys.
' *
' * @param paramList Variant list of parameters with parameter names as keys.
' */
End Sub ' OpenGeoDBRecord.ReadFromList
Public Sub ReadFromArray(paramArray As Variant)
'/**
' * reads data from an array
' *
' * @param paramArray String array of parameters.
' */
End Sub ' OpenGeoDBRecord.ReadFromArray
Public Sub ReadFromDoc(openGeoDoc As NotesDocument)
'/**
' * reads data from a document
' *
' * @param openGeoDoc NotesDocument object to read from.
' */
End Sub ' OpenGeoDBRecord.ReadFromDoc
Public Sub ReadFromViewEntry(openGeoEntry As NotesViewEntry)
'/**
' * reads data from a view entry (more efficient than from a NotesDocument)
' *
' * @param openGeoDoc NotesViewEntry object to read from.
' */
End Sub ' OpenGeoDBRecord.ReadFromViewEntry
End Class ' OpenGeoDBRecord
Please mind the typecast using the typed variables.
Instead of the IsA operator you can of course also use TypeName(source) = "NOTESDOCUMENT" and accordingly = "NOTESVIEWENTRY".
Private Class OpenGeoDBRecord
Public Sub New(source As Variant)
Dim openGeoDoc As NotesDocument
Dim openGeoEntry As NotesViewEntry
If TypeName(source) = "VARIANT LIST" Then
Call ReadFromList(source)
ElseIf TypeName(source) = "STRING( )" Then
Call ReadFromArray(source)
ElseIf source Is Nothing Then
' initialize with default values...
ElseIf source IsA "NotesDocument" Then
Set openGeoDoc = source
Call ReadFromDoc(openGeoDoc)
ElseIf source IsA "NotesViewEntry" Then
Set openGeoEntry = source
Call ReadFromViewEntry(openGeoEntry)
End If
End Sub ' OpenGeoDBRecord.New
Public Sub ReadFromList(paramList As Variant)
'/**
' * reads data from a list with the parameter names as keys.
' *
' * @param paramList Variant list of parameters with parameter names as keys.
' */
End Sub ' OpenGeoDBRecord.ReadFromList
Public Sub ReadFromArray(paramArray As Variant)
'/**
' * reads data from an array
' *
' * @param paramArray String array of parameters.
' */
End Sub ' OpenGeoDBRecord.ReadFromArray
Public Sub ReadFromDoc(openGeoDoc As NotesDocument)
'/**
' * reads data from a document
' *
' * @param openGeoDoc NotesDocument object to read from.
' */
End Sub ' OpenGeoDBRecord.ReadFromDoc
Public Sub ReadFromViewEntry(openGeoEntry As NotesViewEntry)
'/**
' * reads data from a view entry (more efficient than from a NotesDocument)
' *
' * @param openGeoDoc NotesViewEntry object to read from.
' */
End Sub ' OpenGeoDBRecord.ReadFromViewEntry
End Class ' OpenGeoDBRecord
Please mind the typecast using the typed variables.
Instead of the IsA operator you can of course also use TypeName(source) = "NOTESDOCUMENT" and accordingly = "NOTESVIEWENTRY".

Comments