A method's signature uniquely
identifies it to the SCL compiler. A method's signature is comprised
of the method's name, its arguments, and their types and order. Precise
identification of a method based on these parameters is necessary
when overloaded methods are used (see
Overloading Methods).
For example, the following
SCL METHOD statements show methods that have different signatures:
Method1: method name:char number:num; endmethod;
Method2: method number:num name:char; endmethod;
Method3: method name:char; endmethod;
Method4: method return=num; endmethod;
Each
method signature is a unique combination, varying by argument number
and type:
-
The first signature contains a
character argument and a numeric argument.
-
The second signature contains a
numeric argument and a character argument.
-
The third signature contains a
single character argument.
-
The fourth signature contains no
arguments.
Signatures in
SAS/AF software are usually represented by a shorthand notation, called
a
sigstring. This sigstring is stored in
the method metadata as SIGSTRING. For example, the four method statements
above have the following sigstrings:
Method1 sigstring: (CN)V
Method2 sigstring: (NC)V
Method3 sigstring: (C)V
Method4 sigstring: ()N
The parentheses group the arguments
and indicate the type of each argument. The value outside the parentheses
represents the return argument. The V character (for “void”)
indicates that no return value is used. A notation that has a value
other than V indicates that the signature has a return value of that
particular type. For example, Method4, above, returns a numeric value.
Although the optional
return variable is listed as part of the sigstring, it is listed only
for convenience and should not be understood as part of the actual
signature. In a sigstring, neither the presence of a return variable
nor its type affects the method signature.
When a method is called,
the SAS SCL compiler matches the arguments in the call to the arguments
in the actual method. Thus, calling the method with the (CN)V signature
actually executes Method1, below. Calling the method with the (NC)V
arguments executes Method2:
/* Method1 */
/* Responds to calls using the (CN)V signature */
object.setColNum('colname', num);
/* Method2 */
/* Responds to calls using the (NC)V signature */
object.setColNum(num, 'colname');
If a method has a return
value, you can execute that method and use the value that it returns
in an assignment. For example, consider an object that has a method
with a signature
()N
. The following are valid
operations:
dcl num returnVal;
returnVal=object.getData();
or
if object.getData() > 1 then do ...
or
if ( object.getData() ) then do ...
Defining signatures
for methods helps other developers understand the method syntax while
also offering enhanced compile-time checking and run-time efficiency.
The default signature for methods is
()V
,
meaning that no arguments are passed into the method and no values
are returned.
Although the SCL compiler
uses the method name to help uniquely identify a method, the name
is not formally part of the signature metadata. In other words, although
a method's signature includes its name and arguments (and their types
and order), the signature metadata itself consists of
Just like return variables,
the usage and description of an argument are not used to differentiate
methods, and are not part of a method's signature, even though they
are part of the signature metadata.
Once you define a signature
for a method and deploy the class that contains it for public use,
you should not alter the signature of the method in future versions
of the class. Doing so could result in program halts for users who
have already compiled their applications. Instead of altering an existing
signature, you should overload the method to use the desired signature,
leaving the previous signature intact.