LOTUSSCRIPT LANGUAGE


Derived Classes
A derived class is created from a previously defined class.

The syntax is:

[ Public | Private ] Class className As baseClass


End Class
ElementDescription
Public, PrivatePublic makes the derived class accessible outside the module in which it is defined. Private (default) makes the derived class accessible only within the module in which it is defined.
classNameThe name of the derived class.
baseClassThe name of the base class from which this class is derived.
classBodyMember variables can have any data type LotusScript supports and can be object reference variables of the class being defined. You can also specify properties, functions, and subs, including Sub New, which initializes class objects, and Sub Delete, which deletes class objects. You cannot declare a class member as Static.


Here is a derived class called MyClass2 that uses the base class MyClass1:

Class MyClass1                  ' Base class.
     a As Integer
     Public c As Integer
     '...
End Class

Class MyClass2 As MyClass1     ' Class derived from MyClass1.
     b As Integer
     Public d As Integer
     '...
End Class
Dim x As New MyClass ' Object x has members
                    ' a%, b%, c%, and d%.
x.c% = 12
x.d% = 35
'...

Usually you use a derived class when an existing class provides members that the new class can use, or when you want to extend or embellish existing class properties and methods. This is called inheritance: the new class inherits, and has direct access to, all Public and Private members of the existing base class.

For example, you want to create derived classes called CheckingAccount, SavingsAccount, BrokerageAccount, and RetirementAccount based on an existing Account class. Because the derived classes can access all existing properties and methods for the Account class, such as AccountNumber, Balance, and DepositMoney, you can reuse all Account class scripts in the new classes.

Demonstrates derived classes inheriting the Properties and Methods of a base class

You can define new member variables, properties, and methods in a derived class to add operations that the derived classes can use. For example, you can add BuyStock and SellStock methods to the BrokerageAccount class.

A derived class can serve as the base class for another derived class. For example, the following illustration shows how the Contractor class, which is derived from the Employee class, serves as the base class for the Subcontractor class. The Subcontractor class has access to the members of both the Contractor class and the Employee class.

Demonstrates hierarchy of base and sub classes, using Employee, Contractor, and SubContractor classes

A derived class has the same scope as its base class, except that a derived class cannot access the Sub Delete of its base class.

See Also