INTERFACE
An interface is defined by a list of methods for a type.
Syntax
INTERFACE
method-name (
parameter-name data-type
[,...]
)
[ RETURNS { data-type
| ( [ data-type [,...] ] )
} ]
[,...]
END INTERFACE
- method-name defines the name of a method.
- parameter-name is the name of a formal argument of the method.
- data-type can be a primitive data type, a user defined type, a built-in class, an imported package class, or a Java class.
Usage
An INTERFACE
structure defines a list of methods that apply to types.
The interface defines the how, the type defines the what.
An interface is associated to a type through the list of methods defined for that type.
An interface is typically defined as a type to simplify its
reusage:
TYPE Shape INTERFACE
area() RETURNS FLOAT,
kind() RETURNS STRING
END INTERFACE
Methods of multiple individual types associated to an interface can be invoked indirectly by
declaring a variable with the interface
structure:
DEFINE s Shape
CALL s.area() -- Can be the area() method for types Circle, Rectangle, etc.
Several interfaces can be defined for a given type. This provides a high level of
flexibility:
TYPE Shape INTERFACE
area() RETURNS FLOAT
END INTERFACE
TYPE Domain INTERFACE
domainName() RETURNS STRING
END INTERFACE
...
DEFINE r Rectangle = ( height:10, width:20 )
DEFINE v1 Shape
DEFINE v2 Domain
LET v1 = r
DISPLAY v1.area()
LET v2 = r
DISPLAY v2.domainName()