User-defined classes

You can build object-oriented applications by creating classes. A class is a data type that restricts access to its data to a set of procedures. These procedures control the ways that an instance of a class (an object) is initialized, accessed, and finally deleted when it is no longer needed.

You can create two types of LotusScript® classes:

  • Base class

    Defines common member variables, properties, and methods that can be inherited by other classes.

  • Derived class

    Extends and elaborates an existing base class. A derived class has direct access to all members of the existing base class. However, the derived class can add new member variables, properties, and methods, and it can redefine properties and methods from the base class, while leaving the base class unchanged. For example, you could create SavingsAccount and CheckingAccount classes based on an Account class.

A class lets your application model real objects, their attributes, and their behaviors. For example, an air traffic-control system creates a flight class, a car rental system creates a car class, and a bank's automated teller system creates an account class. For each class, you define its members: variables, properties, and subs and functions (also called methods). Typically, you can retrieve and assign values to an object's properties. Methods perform operations on the object.

Class

Properties

Methods

Flight

GateNumber

FlightNumber

InAir

OnGround

TakeOff

Land

DelayFlight

CancelFlight

Car

LicensePlate

DriverLicense

RentalDate

ServiceCar

TransferLocation

Account

CustomerNumber

Balance

AccountNumber

WithdrawCash

DepositMoney

MoveMoney

In a script, you can declare a variable to refer to an instance of the object's class. The variable is an object reference variable. Each class defines the data used by instances of the class and defines a set of properties and methods that apply to the class.

Benefits of classes

Classes offer several features that can simplify your application programming:

  • Classes provide more functionality than any other LotusScript® data type. A class can hold any type of data, including instances of the class being defined.
  • Classes are self-contained so it's easy to use the same class in another application. For example, a File class that provides general file input/output functions can be shared with other applications. Reusing classes reduces the time to design, write, and test your application, increases the likelihood that your scripts are correct, and saves time when you need to update scripts.
  • You can simplify the programming interface to your application by creating classes that call the Windows API (Application Programming Interface), or any C-API. Users work only with the member variables, properties, and methods of the class, and do not require knowledge of Windows or C-API programming.
  • You can build class libraries (a collection of classes) to allow other application developers to use your classes without allowing them to modify the class scripts. To do this, you compile classes into .LSO files and provide access via the Use statement.
  • You can use classes to build tools for your applications. For example, you can create a class that allows your application to access the spelling checker and dictionary that come with most IBM® software.