Adding Conditions to Classes or Primitive Types

A conditional expression is a restricted form of a method. The major use of a condition is as a constraint, which is used to maintain automatic inverse references when a specified condition is satisfied. When defining conditions, note the following.

For examples of conditions and constraints, see "Condition Examples", in the following subsection.

Before you define a new condition, you must select the class or primitive type to which the method is to be added.

Conditions cannot involve reference properties.

To add a condition to a class or primitive type

  1. In the Class List of the Class Browser or the Primitive Types List of the Primitive Types Browser, click on the class or primitive type for which the condition is to be added.

  2. Select the New Condition command from the Methods menu. (This command is enabled only when the All or Instance sheet has focus.)

    The Add Condition dialog is then displayed.

  3. Specify the name of your new condition in the Name text box. The name value must start with a lowercase character and the name must be unique to the class or primitive type to which it is being added.

  4. Check the Protected check box if you want the protected condition option added to the signature of your condition so that it can be referenced only by methods or conditions in the same class or its subclasses.

    By default, conditions are not protected.

    A padlock symbol is not displayed to the left of the condition name in the browser Methods List. To determine if an existing condition is protected, select the condition in the Methods List and see whether the protected option is displayed in the condition signature in the editor pane.

  5. Check the Subschema Hidden check box if you want to specify that the condition is available only in the local schema; that is, it is not available for use in any subschemas. For details, see "subschemaHidden Option" under "Controlling the Use of Elements in Other Schemas", in Chapter 1.

  6. Click the Enter Text button if you want to specify or maintain descriptive text for the condition as part of the definition or maintenance of the condition. For details, see "Specifying Text for a Schema Element", in Chapter 3.

    You can also specify descriptive text for the condition at any time, by selecting the Text command from the Methods menu. For details, see "Using the Free-Standing Editor Window to Define Text", in Chapter 3.

  7. Click the OK button or the Next button.

A template for the condition is then displayed in the editor pane of the browser window.

The error symbol is displayed to the left of the condition name in the Methods List until you have specified any parameters that you require and the boolean-expression return value for the condition, and then compiled it.

If a method template has been defined for all new methods and conditions in your JADE development database or for your own JADE methods and conditions, the defined method template is displayed in the editor pane. For details, see "Maintaining Text Templates", in Chapter 2.

A condition has the following syntax.

condition-name([parameters]): Boolean condition;
[constants
    constant-declarations]
begin
    condition-instructions;
end;

Only if and return instructions can be used in condition methods. A returned boolean-expression can contain only references to the properties of the class and calls to other conditional expressions.

This syntax (with the exception of the optional parameters and constant-declarations) is automatically displayed with the return instruction in the editor pane when you click the OK button in the Add Condition dialog unless a method template is defined for your JADE development environment, in which case the editor pane display is determined by the template.

A condition cannot use array indexing ([index]) or dictionary indexing ([key, key, ...]).

You can define optional parameters only for conditions that are not constraints, and the parameters must be constant values. For more details, see "Parameters" under "JADE Language Syntax", in Chapter 1 of the JADE Developer’s Reference.

Modify the template by specifying the boolean expression that you require following the return instruction to perform the required operations or replace the return instruction with the appropriate if instruction.

When you have specified the boolean expression to return or the if condition and any constant parameters that you require for a condition that is not a constraint, compile the condition. (For details, see "Compiling Methods", later in this section.)

When you have compiled the condition, the condition symbol is then displayed to the left of the condition name in the Methods List.

The following image shows an example of a condition.