Chapter Contents

Previous

Next
INTERFACE

INTERFACE



Defines a group of abstract methods shared by the related classes

Category: Object Oriented


Syntax
Details
Examples
Example 1: Defining a Simple Interface
Example 2: Defining Classes That Support Interfaces
Example 3: Defining Classes That Require Interfaces
See Also

Syntax

INTERFACE interface-name
<EXTENDS interface-name>
</ (interface-optional-clause)>;
<(limited-method-declaration-statements)>
ENDINTERFACE;

interface-name
is the name of the interface that you are defining, which can be specified as a one- to four-level name. The entry type is INTERFACE.

EXTENDS-interface-name
specifies the parent interfaces as a one- to four-level name. An interface can inherit from parent interfaces. If you do not use the EXTENDS clause, the parent-interface defaults to SAS HELP.FSP.INTERFACE.CLASS.

interface-optional-clause
specifies options for the interface. You must put the list inside the parentheses that follow a / (slash). Separate multiple options with commas. The only option currently supported is

Description = description
is a description of the INTERFACE entry.

limited-method-declaration-statements
defines the interface methods. Declare the methods as follows:
method-label-name: METHOD <argument-list><OPTIONAL=argument-list>
</(method-options)>;

method-label-name
can be up to 32 characters and has the same restrictions as an SCL label.

argument-list
list one or more sets of arguments, with each set specified as follows:
var-list <:INPUT|UPDATE|OUTPUT>:data-type(length)

var-list
lists one or more variables to contain values that are passed in from a method call using either dot notation or the METHOD, SEND, SUPER, APPLY or SUPAPPLY routine or function. Variables can also be reference arrays. Reference array dimensions are specified by '*'. Use commas to separate '*' for multiple dimensions. The actual size of the reference array will be determined at run time based on the dimensions specified in the array parameter of the calling method. For more information, see ARRAY and Reference Array Whose Size Is Determined at Run Time.

INPUT | I
specifies that, at run time, the variable contains the value that is copied from the corresponding parameter of the calling method. However, when the program finishes, the value is not copied back to the calling method.

UPDATE | U
specifies that, at run time, the variable contains the value that is copied from the corresponding parameter of the calling method. When the program finishes, the value is copied back to that parameter.

OUTPUT | O
specifies that, when the program finishes, the value is copied back to the corresponding parameter in the calling program. An error condition results if the corresponding parameter in the calling program is a constant, because a constant cannot receive a value.

data-type
specifies the type of data that the variable will contain. A named data type (for example, CHAR or LIST) must be preceded by the : delimiter. The delimiter is optional for unnamed data types (for example, $).

CHAR<(length)>
specifies that the variable will contain character data. Length can be 1 to 32,767 characters. If length is not provided, the default length is 200.

LIST
specifies that the variable will contain an SCL list identifier.

NUM
specifies that the variable will contain a numeric value.

OBJECT
specifies that the variable will contain the identifier for an object when it is defined at run time.

This type causes the SCL compiler to generate extra conversion instructions. Consequently, you should use it only when necessary so as to achieve optimal run-time performance.

class-name
specifies that the variable will contain the identifier for an object of the class specified in class-name. Class-name must be a three- or four-level name unless an IMPORT statement has specified the libref and catalog. In that case, the name can be a one- to four-level name. If the entry type is not specified, it is assumed to be CLASS.

interface-name
specifies that the variable will contain the identifier for an object of the class that supports the interface specified in interface-name. Interface-name must be a three- or four-level name unless an IMPORT statement has been used to specify the libref and catalog. In that case, the name can be a one- to four-level name.

If the entry type is not specified and a class with that name does not exist, the default entry type of INTERFACE is assumed.

To be compatible with the applications built in earlier releases of SAS software, the : delimiter is optional for variables that have been declared with unnamed data types (for example, $), but it is required for variables that have been assigned named data types. The following example shows a variety of data type declarations, including reference arrays that use * as the dimensions:
mymethod: method
 char1  : Char(20)
   char2  : Char(10)
   char3  :input :char(50)
   charArr(*):u:char /* a reference array */
   num1   : num
   num2   : num
   num3   : num
   numArr(*):num     /* a reference array */
   myList :list
   myObj  :object
   myCol :Sashelp.Fsp.Collection.class ;

Type: Character

length
is a numeric constant that specifies the length of the preceding variable or variables. The length of a character variable does not have to match the length of the corresponding passed parameter. SCL pads or truncates as necessary. When a length is specified for a variable that is declared as CHAR, the length specification must be enclosed in parentheses.

Type: Character

OPTIONAL=
enables you to specify one or more optional arguments that are used only if the calling program supplies the corresponding parameters in the parameter list of the calling routine. If corresponding parameters are not supplied, then the optional arguments are initialized to missing values.

method-options
specify options for an interface method. You must put the list inside parentheses that follow a / (slash). The only option currently supported is Description = description, which may be used to provide a description of the method.


Details

In order to group related classes which share similar method names, a superclass can be created. One approach to create the superclass is to use the INTERFACE block. You can use the INTERFACE and ENDINTERFACE statements to create an INTERFACE block that contains method definitions. Method implementations are not allowed in the INTERFACE block, so all methods are defined as abstract methods.

Interfaces describe "contracts" in a pure, abstract form, but an interface is interesting only if a class supports it. Any class that supports an interface must implement all of the methods defined in the interface. Since the INTERFACE block does not contain any method implementations, class developers can use the INTERFACE block to reflect the high- level design of their applications. Any class can also be specified with the "required" interface using the "Required-Clause". The SCL compiler will generate information that will be used to validate whether the actual method used at run time matches the required interface.

To create an interface from an SCL entry that contains an INTERFACE block, you must issue either the SAVECLASS command or from FILE menu Save Class Pmenu. This compiles the entry and creates the INTERFACE entry that is specified by interface-name. This is equivalent to using the Interface Editor to interactively create an INTERFACE entry. However, the Interface Editor provides a tabular view of the interface, whereas the INTERFACE statement in SCL provides a language view of the interface. For maintenance purposes, the existing INTERFACE entry can also be converted to SCL syntax by using the CreateSCL function. For more detailed information, please refer to the CREATESCL function.


Examples

Example 1: Defining a Simple Interface

The following INTERFACE block defines a simple myWidget interface with four GUI methods.

interface work.a.myWidget.interface;
     refresh: method;
     needRefresh: method;
     select: method;
     tab: method n1:NUM n2:NUM;
endinterface;
The following INTERFACE block defines an I/O interface with two I/O methods.
interface work.a.myIO.
interface;
  read: method string buffer;
  write: method string buffer;
endinterface;

Example 2: Defining Classes That Support Interfaces

The INTERFACE blocks cannot contain method implementations, so any class that supports an interface must implement all of the methods defined in the interface. The following class implements methods that are defined in work.a.myIO.interface:

class work.a.model.class supports work.a.myIO.interface;
  read: method string buffer
         / (scl='work.a.model.scl');
  write: method string buffer
          / (scl='work.a.model.scl');
  /* The following method is not in the interface */
  myMethod: method n:Num
          / (scl='work.a.myscl.scl');
endclass;
The following class supports both the myWidget interface and the myIO interface.
class work.a.modelViewer.class
      supports work.a.myWidget.interface,
                work.a.myIO.interface;
  refresh: method / (scl='work.a.mv.scl');
  needRefresh: method / (scl='work.a.mv.scl');
  select: method / (scl='work.a.mv.scl');
  tab: method n1:NUM n2:NUM
        / (scl='work.a.mv.scl');
  read: method string buffer
         / (scl='work.a.model.scl');
  write: method string buffer
          / (scl='work.a.model.scl');
  myMethod: method n: num
          / (scl='work.a.myscl.scl');
endclass;

Example 3: Defining Classes That Require Interfaces

The following class requires both the myWidget interface and the myIO interface. By specifying which interfaces are required, you allow the SCL compiler to generate information that will be used to validate whether the actual methods used at run time matched the required interface.

class work.a.myRequired.class
      Requires work.a.myWidget.interface,
               work.a.myIO.interface;
   ...Other implementations...
endClass;

See Also

CLASS


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.