To invoke a method:
Use call or start exactly as you would for a procedure.
call statement, see call. For information about the start action, see start. The differences between call and start are the same for methods and procedures.
Invoking a Method Generically
When you invoke a method generically, G2 selects the particular method to invoke.
To invoke a method generically:
Specify an operation name in a call statement or start action.
For example, suppose that:
flask-1 is an object of class flask
success is a truth-value
fill method is as described in the vessel example.
fill on a flask by executing:
success = call fill (flask-1)
flask and its parent vessel each has a fill method. Since every class appears first in its own inheritance path, G2 invokes the method for flask, sending it the arguments flask-1.
The types of any additional arguments, and the number and type(s) of any return values, are not significant for selecting which method to invoke. However, they must match whichever method G2 actually invokes, or G2 signals an error, as with a similar mismatch in an ordinary procedure invocation.
class-name::method-name
fill method for flask is:
flask::fill
call statement or start action. G2 then invokes exactly the designated method. If the method does not exist, G2 signals an error: it does not search the inheritance path of the class specified in the generic name.For example, suppose that:
flask-1 is an object of class flask
fill method is as described in the vessel example.
flask::fill performs, and fill the flask directly, via vessel::fill.
call vessel::fill (flask-1)
fill method for vessel on the object flask-1.The
call next method statement has the same effect whether the method that contains it was invoked generically or directly, as described under Invoking a Superior Method (call next method).
Optional Direct Invocation
You can use direct invocation even where generic invocation would have the same effect. Such invocation, though initially unnecessary, ensures that your code will always call the particular method despite subsequent changes to the class hierarchy. Using direct invocation does not protect against changes to the effect of executing call next method.
success = call flask::fill (flask-1)
success = call fill (flask-1)
flask::fill no matter how the class hierarchy changes, while the latter might cease to do so. However, such a change in the hierarchy might in either case change the effect of call next method.
Direct invocation allows you to invoke a method on an item whose class differs from that of the first argument defined by the method. Such an invocation is correct if the item belongs to a subclass of the argument class, but not if it belongs to a superior class.
That is, you cannot directly invoke a method on an item whose class is superior to the class for which the method is defined. If you attempt to violate this restriction, G2 signals an error.
This restriction exists because an instance of a superior class may not have all of the attributes needed by a method or procedure designed for use with an inferior class: additional attributes may be added lower in the hierarchy.
call next method statement to cause one method to call another that is defined for a superior class. The statement allows you to specify behavior hierarchically, as described under Designing a Class Hierarchy.
The syntax of the
call next method statement is:
[return-value [, ...] ] = call next method
flask::fill method shown earlier included:
OK = call next method
call next method statement as follows:
A
call next method statement is similar to an ordinary call statement. Specifically:
call next method statement applies only to methods: it cannot appear in a procedure.