The Alf editor may be used to create an Alf body for a new Opaque Behavior or to edit the existing Alf body of an Opaque Behavior. The Alf code for an Opaque Behavior is stored as the body of the Opaque Behavior with the language Alf. Compiling this Alf code results in the creation of an executable Activity reflecting the behavior defined by the Alf code. This Activity is attached to the Opaque Behavior as a tagged value of the special CompiledRepresentation stereotype. (See also the discussion on the Alf compiler.)

A Function Behavior is simply a special kind of Opaque Behavior that should produce a return value and have no side effects. The procedures below apply to Function Behaviors as well as Opaque Behaviors.


To create an Opaque Behavior with an Alf body


  1. Create an Opaque Behavior in the Model Browser.
  2. Add Parameters to the Opaque Behavior as desired.

    The easiest way to create an Opaque Behavior with Parameters is to type the complete signature for the Opaque Behavior with its name when you create it. For example, if you type "Compute(x: Integer): Integer" for the Opaque Behavior name, this results in an Opaque Behavior named "Compute" with an Integer input parameter named x and a return type of Integer. Parameter declarations may also be prefixed with in, out or inout to specify the Parameter direction.

  3. Select the Opaque Behavior in the Model Browser and open the Alf editor window (select Windows > Alf), if it isn't already open.

  4. Enter the Alf code for the Opaque Behavior and press Save to compile and save the code.


To edit an existing Alf body for an Opaque Behavior


  • Select the Opaque Behavior in the Model Browser and open the Alf editor window (select Windows > Alf), if it isn't already open. The existing Alf code will be displayed in the window.

The Alf code for an Opaque Behavior can also be entered or edited directly in the Body and Language property in the Specification window for the Opaque Behavior. If you open the Edit Body and Language window, then the Alf code may be edited just as in the Alf editor window. However, instead of Save and Revert buttons, this window has OK and Cancel buttons, either of which will close it. If you press OK, then the text is saved, and, if it has no errors, compiled. If you press Cancel, the Alf text is not saved.

Editing Alf in an Opaque Behavior body

To be recognized as Alf code, the Body of an Opaque Behavior must have the Language Alf. If your project was created using the Alf project template, then Alf will be the default language. Otherwise, select Alf from the Language menu (you may have to scroll upwards in the menu to find the selection for Alf).

To make Alf the default language for Opaque Behaviors


  1. Select Options > Project.
  2. On the left, under Default model properties, select Opaque Behavior.
  3. Click on the Language field and then on the small + button on the right.
  4. Enter Alf (spelled and capitalized in exactly that way) and press OK.
  5. Press OK to close the options window.