Chapter 3. Directives

Table of Contents
::ATTRIBUTE
::CLASS
::METHOD
::REQUIRES
::ROUTINE

A Rexx program contains one or more executable code units. Directive instructions separate these executable units. A directive begins with a double colon (::) and is a nonexecutable instruction. For example, it cannot appear in a string for the INTERPRET instruction to be interpreted. The first directive instruction in a program marks the end of the main executable section of the program.

For a program containing directives, all directives are processed first to set up the program's classes, methods, and routines. Then any program code in the main code unit (preceding the first directive) is processed. This code can use any classes, methods, and routines that the directives established.

::ATTRIBUTE

The ::ATTRIBUTE directive creates attribute methods and defines the method properties.

>>-::ATTRIBUTE--name--+-----+-------+-------+------------------------->
                      +-GET-+       +-CLASS-+
                      +-SET-+

    +-PUBLIC--+  +-GUARDED---+  +-UNPROTECTED-+
 >--+---------+--+-----------+--+-------------+--;----------------><
    +-PRIVATE-+  +-UNGUARDED-+  +-PROTECTED---+

Note: You can specify all options in any order.

An ::ATTRIBUTE directive starts an attribute method, which is ended by another directive or the end of the program. The ::ATTRIBUTE is not included in the method source.

The name is a literal string or a symbol that is taken as a constant. The name must also be a valid Rexx variable name. The ::ATTRIBUTE directive creates methods in the class specified in the most recent ::CLASS directive.

A ::CLASS directive is not required before an ::ATTRIBUTE directive. If no ::CLASS directive precedes ::ATTRIBUTE, the attribute methods are not associated with a class but are accessible to the main (executable) part of a program through the .METHODS built-in object. Only one ::ATTRIBUTE directive can appear for any method name not associated with a class. See .METHODS for more details.

If you do not specify either SET or GET, ::ATTRIBUTE will create two attribute methods with the names name and name=. These are the methods for getting and setting an attribute. These generated methods are equivalent to the following code sequences:

::method "NAME="  /* attribute set method                                   */
  expose name     /* establish direct access to object variable (attribute) */
  use arg name    /* retrieve argument and assign it to the object variable */

::method name     /* attribute get method */
  expose name     /* establish direct access to object variable (attribute) */
  return name     /* return object's current value                          */

Both methods will be created with the same method properties (for example, PRIVATE, GUARDED, etc.). If GET or SET are not specified, another directive (or the end of the program) must follow the ::ATTRIBUTE directive.

If GET or SET is specified, only the single get or set attribute method is generated. Specifying separate GET or SET ::ATTRIBUTE directives allows the methods to be created with different properties. For example, the sequence:

::attribute name get
::attribute name set private

will create a NAME method with PUBLIC access and a NAME= method with PRIVATE access.

The GET and SET options may also be used to override the default method body generated for the attribute. This is frequently used so the SET attribute method can perform new value validation.

::attribute size get
::attribute size set
  expose size     /* establish direct access to object variable (attribute) */
  use arg value   /* retrieve argument                                      */
  if datatype(size, "Whole") = .false | size < 0  then
    raise syntax 93.906 array ("size", value)
  size=value

If you specify the CLASS option, the create methods are class methods. See Objects and Classes. The attribute methods are associated with the class specified on the most recent ::CLASS directive. The ::CLASS directive is required in this case.

If you specify the PRIVATE option, the methods are private methods. (Only a message the same object sends can activate the methods.) If you omit the PRIVATE option or specify PUBLIC, the methods are public methods that any sender can activate.

If you specify the UNGUARDED option, the methods can be called while other methods are active on the same object. If you do not specify UNGUARDED, the method requires exclusive use of the object variable pool; they can run only if no other method that requires exclusive use of the object variable pool is active on the same object.

If you specify the PROTECTED option, the method is a protected method. (See The Security Manager for more information.) If you omit the PROTECTED option or specify UNPROTECTED, the method is not protected.

Note: It is an error to specify ::ATTRIBUTE more than once within the same class and to define the name set or get method.