Properties as top level members of script libraries

Is anyone actually using the possibility of defining a Property as a top level member in a LotusScript script library? Apparent you are able to define a property as a top level member of a script library just as it is possible with a Sub or Function. The below code will actually compile and run (“SomeProperty” is not a variable but actually a Property defined in the Declarations section).

Sub Initialize
   SomeProperty = "HelloWorld"
   Msgbox SomeProperty
End Sub

Below is how the code actually looks in Domino Designer with “value” being a String variable defined in the Declarations section. Although possible I wonder if anyone actually uses it as I think it makes the code a little difficult to read.


Published by

lekkim

Positive, competent, out-spoken, frank and customer focused architect and developer with a strong foundation in web, cloud and product development. I'm a strong advocate for API first and cloud based solutions and development. I have a knack for being able to communicate and present technically complicated matters in conference, customer and training settings. I've previously acted as team member and leader in a product organisation.

7 thoughts on “Properties as top level members of script libraries”

  1. I don’t use public properties at all. I prefer to use getter and setter methods for better encapsulation.
    I’d rather have the class itself decide if and how a property might be modified.

  2. Used in a custom class, it can provide a slightly better overview of class’s functionality. Outside classes it’s rather useless. It’s like using “Let” statement for setting variables: it works, but why bother?

    Dim x As Integer
    Let x=3

  3. We do not use Properties at all, since you can’t name the private attribute the same as the property. We prefer the “Java syntax” and real functions and subs as getters and setters.

    But if you consider using script libraries as a possibility to implement the Singleton design pattern, it would be “normal” to use Getters and Setters for its attributes.

    Stretching this idea a little further, you could think of a script library “SomeClass” containing just one class definition “SomeClass” as the Class object of this class. Then its attributes and “methods” would be the static attributes and static methods of this class.

    For example:
    ‘ script library SomeClass

    Public Class SomeClass

    Public Sub New()
    ‘ …
    End Sub

    End Class

    Private instance As SomeClass

    Private instancesCreated As Long

    Function GetInstance() As SomeClass
    If (instance Is Nothing) Then
    Set instance = New SomeClass()
    End If

    instancesCreated = instancesCreated + 1
    Set GetInstance = instance
    End Function

    You can’t make the constructor of SomeClass private, and since there are no namespaces, you probably can’t name the sub just “GetInstance” without getting conflicts, but I think, you get the picture.

  4. Actually you can distinguish the members and the property using the Me keyword inside class scope subs, functions and properties (e.g. Me.firstname). I find your concept of using global properties and subs / functions of a script library to create singleton-style objects intriguing and interesting. Good point although the use is probably restricted. Thanks for chiming in… 😉

  5. Well I didn’t mean public class members but actually properties defined in a script library at the same level as subs and functions. Try writing “Public Property Get SomeProperty As String” in the Declarations section of a script library and see what happens once you press Enter.

  6. What I meant is this:

    Public Class TestClass
      Private testAttribute As Integer
    
      Public Property Get testAttribute As Integer
       testAttribute = Me.testAttribute
      End Property
    End Class
    

    This class won’t compile with following error:
    Name previously declared: TESTATTRIBUTE

    So I use this:

    Public Class TestClass
      Private testAttribute As Integer
    
      Public Function GetTestAttribute As Integer
       GetTestAttribute = Me.testAttribute
      End Function
    End Class
    

    Ciao
    Thomas

Comments are closed.