Defining Classes
Before you can declare an object (an instance of a class), your procedure must have a class definition for that type of object. If the class:
- Is already defined in a class library, simply import the library into your procedure. Class libraries, which are implemented as import modules, are described in Reusing Classes: Class Libraries.
- Is already defined in another procedure, simply copy and paste the definition into a class library. You can then import the library into any procedure that needs it.
- Is not yet defined anywhere, you can define it in a class library or procedure using the Class Editor, or by coding the definition directly in the Procedure Editor, using the DESCRIBE command. If you define it in a class library, you can use the class definition in multiple procedures by simply importing the library into those procedures.
Define a Class Using the Class Editor
This procedure describes how to define a new class. If you wish to define a new subclass, that is, a class that inherits properties from another class, see Defining Classes.
- Procedure
- In the Requests & Data Sources panel, right-click the import module or procedure and select New class in the shortcut menu.
- In the New Class dialog box, type a name for your class.
- Click the Variables tab to specify the member variables of a class. The member variables of a class express its properties.
- To add
a variable, click the New button
.
The Member Variable dialog box opens.
The name of each member variable must be unique within the class to which it belongs. It can be identical, however, to the names of member variables of other classes.
- Repeat step 4 to create any additional variables.
- Click the Functions tab to specify the member functions of a class. The member functions of a class define the actions that can be performed on the objects of a class.
- To add
a function, click the New button
.
The Member Function dialog box opens.
The name of each member function must be unique within the class to which it belongs. It can be identical, however, to the names of member functions of other classes.
- Repeat step 7 to create any additional functions.
- Optionally, click the Description tab and add a description to your class.
- Click OK to confirm the class definition.
Define a Subclass Using the Class Editor
To define a new class (a subclass) by inheriting properties (member functions and member variables) from another class (a superclass):
- Procedure
- In the Requests & Data Sources panel, right-click the import module or procedure and select Class (Describe) in the submenu.
- In the New Class dialog box, type a name for your class.
- Select the class whose properties the new class will inherit from the Inherits behavior from list. You can choose from all of the classes that are defined in this import module or procedure, and in any modules that have been imported into it. The selected class will be the superclass, and the new class will be the subclass.
- Click the Variables tab to specify the member variables of a class. The member variables of a class express its properties. A subclass inherits all the member variables of its superclass, and you can add new ones.
- To add
a variable, click the New button
.
The Member Variable dialog box opens.
Note: You cannot delete member variables inherited from the superclass. - Repeat step 5 to create any additional variables.
- Click
the Functions tab to specify the member functions
of a class. The member functions of a class define the actions that
can be performed on the objects of a class.
Note that you cannot delete member functions inherited from the superclass. However, you can override an inherited member function it to edit or remove its source code.
- To add
a function, click the New button
.
The Member Function dialog box opens.
The name of each member function must be unique within the class to which it belongs. It can be identical, however, to the names of member functions of other classes.
- Repeat step 8 to create any additional functions.
- Optionally, click the Description tab and add a description of the class.
- Click OK to confirm the class definition.
Define a Class or Subclass Using the DESCRIBE Command
When you define a class using the Class Editor, it generates the definition in the procedure as a DESCRIBE command. If you wish to work directly with source code, you can create new class definitions and edit existing definitions directly in the Procedure Editor by using the following DESCRIBE syntax. You must issue the DESCRIBE command outside of a function, for example, at the beginning of the procedure prior to all functions.
DESCRIBE classname = ([superclass +] memvar/type [, memvar/type] ...) [;] [memfunction [memfunction]... ENDDESCRIBE]
where:
Is the name of the class that you are defining. The name is subject to the standard naming rules of the Maintain Data language.
Is the name of the superclass from which you wish to derive this class. Include only if this definition is to define a subclass.
Names one of the member variables of the class. The name is subject to the Maintain Data language standard naming rules.
Is a data type (a built-in format or a class).
Defines one of the class member functions. Member functions are defined the same way as other Maintain Data functions, using the CASE command.
Terminates the definition if the definition omits member functions. If it includes member functions, the semicolon (;) is omitted and the ENDDESCRIBE command is required.
Ends the class definition if it includes member functions. If it omits member functions, the ENDDESCRIBE command must also be omitted, and the definition must be terminated with a semicolon (;).
Edit a Class Definition
To add a new member function or member variable:
- Procedure
- In the Requests & Data Sources panel, right-click the class and select New member, and then select Function or Variable.
- In the New Function or New Variable dialog box, create your new function or variable.
To edit one of the member functions or member variables of a class:
- In the Requests & Data Sources panel, right-click one of the class member functions or member variables.
- In the shortcut menu, click Edit.
- Make any necessary changes to the class definition in the Edit Variable or Member Function dialog boxes. For general information about editing a class definition, see Defining Classes.
- Click OK to confirm your changes.
Edit the Class Source Code
- Procedure
- In the Requests & Data Sources panel, right-click the class.
- In the shortcut menu, click Edit source.
- Make any changes you wish to the code between DESCRIBE classname and ENDDESCRIBE.
- Close the Procedure Editor.
Rename a Class, Member Variable, or Member Function
- Procedure
- In the Requests & Data Sources panel, right-click the class, member variable, or member function, and in the shortcut menu, click Rename.
- Type the new name.
- Press the Enter key to confirm the new name.
Delete a Class, Member Variable, or Member Function
In the Requests & Data Sources panel, right-click the class, member variable, or member function, and in the shortcut menu, click Delete.
New Class and Edit Class Dialog Boxes
The New Class and Edit Class dialog boxes enable you to create and edit classes. An example of the New Class dialog box is shown in the following image.
The New Class dialog box contains the following tabs:
General tab
The General tab has the following options:
Type the name of your class here.
If this class is based on another class, select that class from the list. The list comprises all of the classes that are defined in the open import module or procedure, and in any modules that have been imported into it.
Functions tab
The Functions tab includes the following options:
Lists the names of the member functions of a class.
Opens the Member Function dialog box, where you can define a new function.
Deletes a selected function from the list of functions, or if a function has been overridden, deletes the override.
Moves a selected function up in the list of functions.
Moves a selected function down in the list of functions.
Variables tab
The Variables tab includes the following options:
Lists the class member variables, including those that it has inherited.
Opens the Member Variable dialog box, where you can define a new variable.
Deletes a selected variable from the list of variables. You cannot delete variables that are inherited from another class definition.
Moves a selected variable up in the list of variables.
Moves a selected variable down in the list of variables.
Description tab
The Descriptions tab has the following elements:
You can document the class by typing a description of it in this edit box. Maintain Data will turn your description into a comment in the class definition source code in the procedure or module.