INTERFACES

Basic form

INTERFACES intf.

Extras:

1. ... ABSTRACT METHODS meth_1 ... meth_n

2. ... FINAL METHODS meth_1 ... meth_n

3. ... ALL METHODS ABSTRACT

4. ... ALL METHODS FINAL

5. ... DATA VALUES attr_1 = val_1 ... attr_n = val_n

Effect

Implements an interface in a class or nests an interface in ABAP Objects. Additions 1 - 5 can only be used for the implementation in a class.

You may only use this statement in the public visibility area definition part of a class declaration (see CLASS) or in an interface definition (see INTERFACE).

If you include the INTERFACES intf statement in the declaration part of a class, then the interface intf will be implemented in the public visibility area of the class:

CLASS class DEFINITION.

  PUBLIC SECTION.

    INTERFACES intf [additions].

    ...

ENDCLASS.

This means that the class-specific components of the public visibility area are extended by the interface components.

All the components comp of the interface appear under the name intf~comp in the class and treated exactly the same as class- specific components under this name. Since an interface can be implemented in several classes, these classes all receive the samecomponent extension. The interface methods can however be implemented differently in different classes.

If a class, class, implements an interface intf, an interface reference can be won from a class reference using the iref = cref assignment. cref must be a reference variable of the type class, while iref must be a reference variable of the type intf. You can only address components declared in the interface using this interface reference.

Using the additions 1 - 5 you can adjust several components to meet the requirements of the class.

Example

INTERFACE I1.
   DATA A1 TYPE I ...

   METHODS: M1, M2 ...
ENDINTERFACE.

CLASS C1 DEFINITION.
  PUBLIC SECTION.
    INTERFACES I1.

  PRIVATE SECTION.

    DATA A1 TYPE I ...
ENDCLASS.

CLASS C1 IMPLEMENTATION.
  METHOD I1~M1.
    A1 = I1~A1.
  ENDMETHOD.
  METHOD I1~M2.
    ...
  ENDMETHOD.
ENDCLASS.

In this example, the entire public area of the class is defined by methods of the interface I1.

Nesting interfaces

If you include the INTERFACES intf1 statement inside the definition of an interface intf2, then the two interfaces, intf1 und intf2 are nested or combined:

INTERFACE intf1.

  ...

  INTERFACES intf2.

  ...

ENDINTERFACE.

intf1 is a nested interface and intf2 is a component interface of intf1. Component interfaces can be nested themselves. The nesting hierarchy is important for the assignment rules between interface references. However, it is not taken into account when nested interfaces are implemented in classes - when all the interfaces involved are treated equally.

Within the definition of a nested interface, components of component interfaces, that are nested to a depth greater than one level, can only be addressed using Aliases. From outside, you can use interface references and class references that indicate objects with nested interfaces.

Note

Since there are no separate namespaces for global and local interfaces, it is important when creating local interfaces that global and local interfaces with the same name are not combined, because these will not be on the same level when implemented.

Example

INTERFACE I1.

  DATA A1.
ENDINTERFACE.

INTERFACE I2.
  INTERFACES I1.
  ALIASES A21 FOR I1~A1.
  DATA A2 LIKE A21.
ENDINTERFACE.

INTERFACE I3.
  INTERFACES I2.
  ALIASES A31 FOR I2~A21.
  ALIASES A32 FOR I2~A2.
  DATA A3 LIKE A32.
ENDINTERFACE.

CLASS C1 DEFINITION.
  PUBLIC SECTION.
    INTERFACES I3.
ENDCLASS.

DATA: CREF  TYPE REF TO C1,
      IREF1 TYPE REF TO I1,
      IREF2 TYPE REF TO I2,
      IREF3 TYPE REF TO I3.

CREATE OBJECT CREF.

CREF->I1~A1 = '1'.
CREF->I2~A2 = '2'.
CREF->I3~A3 = '3'.

IREF3 = CREF.
IREF2 = IREF3.
IREF1 = IREF2.

WRITE: / IREF1->A1, IREF2->A21, IREF3->A31,
       / IREF2->A2, IREF3->A32,
       / IREF3->A3.

In this example, the interface I1 is a component of I2, which in turn is a component of I3. When I3 is implemented in the class C1, this class contains the components of all three interfaces, as the assignments after the object is instantiated show. Aliases are used to access the components of the component interface. Assignments between the interface references and the WRITE statements show how components can be accessed using interface references.

Additions for Implementation in Classes

Addition 1

... ABSTRACT METHODS meth_1 ... meth_n

Effect

Assigns the property ABSTRACT to the specified instance methods of the interface. See METHODS.

Addition 2

... FINAL METHODS meth_1 ... meth_n

Effect

Assigns the property FINAL to the specified instance methods of the interface. See METHODS.

Addition 3

... ALL METHODS ABSTRACT

Effect

Assigns the property ABSTRACT to all instance methods of the interface. See METHODS.

Addition 4

... ALL METHODS FINAL

Effect

Assigns the property FINAL to all instance methods of the interface. See METHODS.

Addition 5

... DATA VALUES attr_1 = val_1 ... attr_n = val_n

Effect

Assigns initial values to the attributes specified (DATA, CLASS-DATA). The values of constants cannot be changed. The specifications val_n have the same meaning as the VALUE specification in the DATA statement.

Related

CLASS

PUBLIC SECTION

PROTECTED SECTION

PRIVATE SECTION

ENDCLASS

CLASS-DATA

CLASS-METHODS

CLASS-EVENTS

METHODS

EVENTS

INTERFACES

ALIASES

METHOD

ENDMETHOD

INTERFACE

ENDINTERFACE

CREATE OBJECT

CALL METHOD

RAISE EVENT

SET HANDLER

Special variants of other keywords

Additional help

Interfaces