Chapter Contents |
Previous |
Next |
INTERFACE |
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; |
method-label-name: METHOD <argument-list><OPTIONAL=argument-list>
</(method-options)>;
var-list <:INPUT|UPDATE|OUTPUT>:data-type(length)
INPUT
|
I
UPDATE
| U
OUTPUT
| O
:
delimiter. The delimiter is optional
for unnamed data types (for example, $).
CHAR
<(
length)
>LIST
NUM
OBJECT
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.
If the entry type is not specified and a class with that name does not exist, the default entry type of INTERFACE is assumed.
:
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
Type: Character
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 |
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;
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;
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 |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.