Defining Classes

How to:

Reference:

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:

Procedure: How to 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 How to Define a Subclass Using the Class Editor.

  1. In the Requests & Data Sources panel, right-click the import module or procedure and select New class in the shortcut menu.
  2. In the New Class dialog box, type a name for your class.
  3. Click the Variables tab to specify the member variables of a class. The member variables of a class express its properties.
  4. To add a variable, click the New button 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.

  5. Repeat step 4 to create any additional variables.
  6. 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.
  7. To add a function, click the New button 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.

  8. Repeat step 7 to create any additional functions.
  9. Optionally, click the Description tab and add a description to your class.
  10. Click OK to confirm the class definition.

Procedure: How to 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):

  1. In the Requests & Data Sources panel, right-click the import module or procedure and select Class (Describe) in the submenu.
  2. In the New Class dialog box, type a name for your class.
  3. 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.
  4. 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.
  5. To add a variable, click the New button New button.

    The Member Variable dialog box opens.

    Note: You cannot delete member variables inherited from the superclass.

  6. Repeat step 5 to create any additional variables.
  7. 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.

  8. To add a function, click the New button 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.

  9. Repeat step 8 to create any additional functions.
  10. Optionally, click the Description tab and add a description of the class.
  11. Click OK to confirm the class definition.

Syntax: How to 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:

classname

Is the name of the class that you are defining. The name is subject to the standard naming rules of the Maintain Data language.

superclass

Is the name of the superclass from which you wish to derive this class. Include only if this definition is to define a subclass.

memvar

Names one of the member variables of the class. The name is subject to the Maintain Data language standard naming rules.

type

Is a data type (a built-in format or a class).

memfunction

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.

ENDDESCRIBE

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 (;).

Procedure: How to Edit a Class Definition

To add a new member function or member variable:

  1. In the Requests & Data Sources panel, right-click the class and select New member, and then select Function or Variable.
  2. 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:

  1. In the Requests & Data Sources panel, right-click one of the class member functions or member variables.
  2. In the shortcut menu, click Edit.
  3. 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.
  4. Click OK to confirm your changes.

Procedure: How to Edit the Class Source Code

If you wish, you can edit the Maintain Data code directly in the Procedure Editor.

  1. In the Requests & Data Sources panel, right-click the class.
  2. In the shortcut menu, click Edit source.
  3. Make any changes you wish to the code between DESCRIBE classname and ENDDESCRIBE.
  4. Close the Procedure Editor.

Procedure: How to Rename a Class, Member Variable, or Member Function

  1. In the Requests & Data Sources panel, right-click the class, member variable, or member function, and in the shortcut menu, click Rename.
  2. Type the new name.
  3. Press the Enter key to confirm the new name.

Procedure: How to Delete a Class, Member Variable, or Member Function

  1. In the Requests & Data Sources panel, right-click the class, member variable, or member function, and in the shortcut menu, click Delete.

Reference: 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:

Class name

Type the name of your class here.

Inherits behavior from

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:

Member Functions

Lists the names of the member functions of a class.

New button

Opens the Member Function dialog box, where you can define a new function.

Delete button

Deletes a selected function from the list of functions, or if a function has been overridden, deletes the override.

move up button

Moves a selected function up in the list of functions.

move down button

Moves a selected function down in the list of functions.

Variables tab

The Variables tab includes the following options:

Member Variables: (Name/Type)

Lists the class member variables, including those that it has inherited.

New button

Opens the Member Variable dialog box, where you can define a new variable.

Delete button

Deletes a selected variable from the list of variables. You cannot delete variables that are inherited from another class definition.

move up button

Moves a selected variable up in the list of variables.

move down button

Moves a selected variable down in the list of variables.

Description tab

The Descriptions tab has the following elements:

Edit box

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.