Entering content frameProcedure documentation Enhancing Classes with Interfaces Locate the document in its SAP Library structure

Interfaces are extensions to class definitions and provide a uniform point of contact for objects. In contrast to classes, instances cannot be created from interfaces. Instead, classes implement interfaces by implementing all of their methods. You can then address them using either class references or interface references.
Different classes can implement the same interface in different ways by implementing the methods differently. Interfaces thus form the basis for polymorphism in ABAP Objects.

Prerequisites

Both the defining class and the interface were already created in the Class Builder.

Procedure

  1. Select the defining class and change to the Class Editor.
  2. Choose Interfaces.
  3. To add interfaces to a class:

    - Interface
    Definition of 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.

    - Abstract
    Only mark the checkbox if the defining class is an abstract class. This means that all the instance methods of the interface have property
    ABSTRACT . For this reason these interface methods may not be implemented in the defining class. Instead, the derived classes must implement all the interface methods.

    - Final
    Marking the checkbox means that all instance methods of the interface have attribute
    FINAL . This means that the interface methods may not be redefined in the subclasses when the classes are inherited.

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

    Example:
    This graphic is explained in the accompanying text

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

Note

You can assign attribute ABSTRACT or FINAL for selected instance methods of the interfaces. To do so, place the cursor on the required interface method in the method display of the enhanced class and go to the detail display of the selected method by choosing This graphic is explained in the accompanying text.

If an interface attribute was included in the class, you can assign the initial value to the attribute in the attribute display of the enhanced class.

Result

You enhanced the components of the class with interfaces. The interfaces that were added are listed in the definition part of the class following the INTERFACES statement in the class pool.
The methods listed in the interface definition can only be implemented within the class if they did not mark the interface as Abstract. 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.

 

Note

You can assign all the components of the interfaces alias names as an abbreviation for the full name. To do so, click on Aliases and enter the alias name. In addition to the name, you can also define the visibility (PUBLIC, PROTECTED, PRIVATE) and thus restrict the use of alias names.

See also:

Implementing Methods

Creating Subclasses

Nesting Interfaces

 

 

Leaving content frame