Public and Private statements

One of the goals of object-oriented programming is to provide a black box, hiding the implementation details from the end user. To assist with this encapsulation of complexity, BSL allows you to hide the methods and properties of an object.

To create methods and properties that are hidden from the end user, precede the properties or methods definition with the Private keyword.

To create methods and properties that are accessible by end user, precede the properties or methods definition with the Public or Dim keyword. If you don’t explicitly specify whether a method or property should be public, dim or private, it will be made public.

However, it is highly recommended that you always explicitly indicate whether a property or method is either Public or Private.

Trying to access private methods or properties through an instance of a Class will result in an error.

Example:


Class Comp
    Private modStrType
    Private Property Let ComputerType(strType)
        modStrType = strType
    End Property
    Public Property Get ComputerType
        ComputerType = modStrType
    End Property
    Private Function Funct1
        'Add business logic using class variables
    End Function
    Public Sub Sub1
        'Add business logic using class variables
    End Sub
End Class

Set objComp = new Comp
objComp.ComputerType = "Mac"	    'Invalid, accessing this property will throw error as it’s private
str1 = objComp.ComputerType 
objComp.Funct1		                 'Invalid, accessing this function will throw error as it’s private
objComp.Sub1