When composing a message, you can change the default search order for methods by doing both of the following:
The scope variable is usually the special variable SUPER, but it can be any environment symbol or variable name whose value is a valid superclass.
In A Sample Program Using Directives , an Account subclass of the Object superclass is created. It defines a TYPE method for Account, and creates the Savings subclass of Account.. The example defines a TYPE method for the Savings subclass, as follows:
::class Savings subclass Account |
::method "TYPE" |
return "a savings account" |
To change the search order so Rexx searches for TYPE in the Account rather than Savings subclass, enter this instead:
::method "TYPE" |
return self~type:super -- returns the result of invoking the TYPE method of the superclass |
When you create an asav instance of the Savings subclass and send a TYPE message to asav:
say asav~type |
Rexx displays:
an account |
rather than:
a savings account |
because Rexx searches for TYPE in the Account class first.