Attaching a Constraint to a Class

A constraint can be attached to a class. In this case, the constraint lies within the scope of instances of the class to which it is attached. For example, the editor-employee-salary-constraint from the newspaper sample project is attached to the Editor class. This means that the constraint-checking engine assumes an implicit range over instances of Editor for all undefined variables. A constraint that has been attached to a class is visible in the Constraints pane of the Class Form for that class. You can attach a constraint to more than one class.

Note: The same restriction to instances of the Editor class is also enforced by the syntax (defrange ?edit :FRAME Editor).  However, attaching a constraint to a class makes the attachment at the Protégé level, and also makes the constraint visible at the class. 

Note: By attaching a constraint to a class, you can make an implicit variable range  definition, that is, you could omit a defrange statement for that variable. This can be used when you want the defrange of the constraint to apply to multiple classes that are not subclasses of a single class, as otherwise you would have to write the constraint in the scope of each class.  However, this should be used with caution, because if a constraint is de-attached from all of its classes, it will lose its implicit range definitions, and will have unbound variables. 

You can attach a constraint to a class in one of three ways:

At the PAL Constraints Tab

To attach a constraint to a class at the PAL Constraints Tab:

  1. Go to the PAL Constraints Tab and make sure the constraint you want to attach to a class is displayed. See Displaying Constraints at the PAL Constraints Tab for more information.
  2. Select the constraint by clicking on it. 
  3. Click the Add button at the top right of the Constraint Attachments pane.



    A Choose class dialog box opens.


  4. Select the class to which you want to attach the constraint and click OK.
    The selected class is displayed in the Attachments pane. You can view the Class Form for the class by selecting it and then clicking the View button in the Attachments pane. You can also see the constraint in the Class Form for that class. See Displaying Attached Constraints at a Class for more information.

At the Classes Tab

To attach a constraint to a class at the Classes Tab:

  1. Go to the Classes Tab.
  2. Highlight the class to which you wish to attach the constraint.
  3. Click the Add button at the upper right of the Class Constraints pane in the Class Form. 
    A Select Instances dialog box opens.


  4. Select :PAL-CONSTRAINT on the left.
  5. Select the constraint(s) you wish to attach to the chosen class on the right.
  6. Click OK.
    The constraint is attached to the class and appears in the list of constraints in the Constraints pane in the Class Form.

For information on how to attach a constraint to a class by creating it at the class, see Creating a Blank Constraint.


PAL Constraints User Interface/Attaching a Constraint to a Class

Next: Removing an Attached Constraint from a Class

PAL Table of Contents