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:


Top of page

x
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. Select the import module or procedure in which you want the class to reside.
  2. Right-click the import module or procedure, click New in the shortcut menu, and click Class (Describe) in the submenu.

    or

    Click the New class button New class button on the Application toolbar.

  3. In the New Class dialog box, type a name for your class.
  4. Click the Variables tab to specify the member variables of a class. The member variables of a class express its properties.
  5. To add a variable, click the New button New button.

    The Member Variable dialog box opens. For instructions on how to create a variable, see How to Create a Variable in a Procedure.

    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.

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

    The Member Function dialog box opens. For instructions on creating functions, see How to Create a Function.

    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 to your class.
  11. Click OK to confirm the class definition.

Top of page

x
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. Select the import module or procedure in which you want the class to reside.
  2. Right-click the import module or procedure, click New in the shortcut menu, and click Class (Describe) in the submenu.

    or

    Click the New class button New class button on the Application toolbar.

  3. In the New Class dialog box, type a name for your class.
  4. 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.
  5. 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.
  6. To add a variable, click the New button New button .

    The Member Variable dialog box opens. For instructions on creating variables, see How to Create a Variable in a Procedure.

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

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

  9. To override an inherited function so that you can later edit its source code, select the function and then click the Override button Override button .
  10. To add a function, click the New button New button .

    The Member Function dialog box opens. For instructions on creating functions, see How to Create a Function.

    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.

  11. Repeat step 10 to create any additional functions.
  12. Optionally, click the Description tab and add a description of the class. This description will be generated as a comment with the class's source code.
  13. Click OK to confirm the class definition.

Top of page

x
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 language. For more information, see the Maintain Language Reference manual.

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 language standard naming rules. For more information, see the Maintain Language Reference manual.

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 functions, using the CASE command. For more information, see the Maintain Language Reference manual.

;

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


Top of page

x
Procedure: How to Edit a Class Definition

To add a new member function or member variable:

  1. Right-click the class in the Project Explorer, click New member, and then click Function or Variable.
  2. In the New Function or New Variable dialog box, create your new function or variable. For instructions on creating functions, see How to Create a Function. For instructions on creating variables, see How to Create a Variable in a Procedure.

To edit one of the member functions or member variables of a class:

  1. Right-click one of the class member functions or member variables in the Project Explorer.
  2. In the shortcut menu, click Edit.
  3. Make any necessary changes to the class's definition in the Edit Variable or Member Function dialog boxes.

    For information about editing variables, see How to Edit a Variable. For information about editing functions, see How to Edit a Function. For general information about editing a class definition, see Defining Classes.

  4. Click OK to confirm your changes.

Top of page

x
Procedure: How to Edit a Class's Source Code

The Maintain Development Environment generates Maintain language code for classes. If you wish, you can edit this code directly in the Procedure Editor.

  1. Right-click the class in the Project Explorer.
  2. In the shortcut menu, click Go to definition.
  3. Make any changes you wish to the code between DESCRIBE classname and ENDDESCRIBE.

    For more information about the DESCRIBE command, see the Maintain Language Reference manual.

  4. Close the Procedure Editor.

Top of page

x
Procedure: How to Rename a Class, Member Variable, or Member Function
  1. Right-click the class, member variable, or member function, and in the shortcut menu, click Rename.

    or

    Select the class, member variable, or member function, and press the F2 key.

    or

    Click the class, member variable, or member function twice.

  2. Type the new name.
  3. Press the Enter key to confirm the new name.

Top of page

x
Procedure: How to Delete a Class, Member Variable, or Member Function
  1. Select the class, member variable, or member function in the Project Explorer.
  2. Right-click the class, member variable, or member function, and in the shortcut menu, click Delete.

    or

    Press the Delete key.

    or

    Click the Delete button Delete button on the General toolbar.


Top of page

x
Reference: New Class and Edit Class Dialog Boxes: General Tab

The New Class and Edit Class dialog boxes enable you to create and edit classes. An example of the General tab is shown in the following image.

New Class dialog box

The General tab has the following options:

Class name

Type the name of your class here. For more information about names, see the Maintain Language Reference manual.

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.


Top of page

x
Reference: New Class and Edit Class Dialog Boxes: Functions Tab

The New Class and Edit Class dialog boxes enable you to create and edit classes. An example of the Functions tab is shown in the following image.

New Class dialog box

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.

Override selected button

Overrides the selected inherited function. You would override a function inherited from a superclass if you wish to make changes to that function in this subclass.


Top of page

x
Reference: New Class and Edit Class Dialog Boxes: Variables Tab

The New Class and Edit Class dialog boxes enables you to create and edit classes. An example of the Variables tab is shown in the following image.

New Class dialog box

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.


Top of page

x
Reference: New Class and Edit Class Dialog Boxes: Description Tab

The New Class and Edit Class dialog boxes enables you to create and edit classes. An example of the Description tab is shown in the following image

New Class dialog box

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 will turn your description into a comment in the class definition source code in the procedure or module.


WebFOCUS