Implementing Interfaces in Classes 

Interfaces are extensions to class definitions and provide a uniform point of contact for objects. Unlike classes, interfaces cannot be instantiated. Instead, classes implement interfaces by implementing all of their methods. You can then address them using either class references or interface references.

Each class can implement interfaces differently by implementing different coding for its methods. Interfaces thus form the basis for polymorphism in ABAP Objects.

Prerequisites

You must have created both the class and interface in the Class Builder.

Procedure

  1. In the Class Builder, open the Class Editor in change mode.
  2. Choose Interfaces.
  3. To add an interface to a class, enter the following information:

    - Interface
    The interface name. When you press Enter, the system checks that the interface exists in the class library. You can use the possible entries help to display a list of all interfaces.

    - Modeled
    If you have selected this option, the system does not enter the interface in the class pool. You cannot access it or its components at runtime.
  4. Repeat steps 1-3 for any further interfaces.

    Example:


  5. If the interface is nested, the system displays all of the component interfaces in the hierarchy after it has checked your input.
  6. Save your entries.

 

Result

You have added one or more interfaces to the components of the class. The interfaces are listed in the definition part of the class in the class pool under the INTERFACES statement.

You must now implement all of the methods listed in the interface within the definition part of the class declaration. For further details, refer to Implementing methods.

The components defined in the interface (attributes, methods, and events) appear in the class in the from <interface name>~<component name>. This ensures that no naming conflicts can occur with class components.