OO ABAP – Interfaces and Polymorphism

Interfaces are simply superclasses that cannot be instantiated, do not have an implementation part, and only have public components. This video will teach you how to define and implement interfaces to use polymorphism in ABAP.

Interfaces are simply superclasses that cannot be instantiated, do not have an implementation part, and only have public components.
This video will teach you how to define and implement interfaces to use polymorphism in ABAP.

Interfaces

  • The only real difference between interfaces and inheritance is the role they play. The programming advantages are thus the same as for inheritance.
  • Interfaces differ from regular inheritance in their area of use. In terms of programming, there are hardly any differences, however.
  • From a technical point of view, interfaces are simply superclasses that:
    • cannot be instantiated,
    • do not have an implementation part,
    • and only have public components
  • In ABAP Objects, interfaces primarily serve to define uniform interfaces for services.
  • Interfaces contain no implementations.
  • In ABAP Objects, the same components can generally be defined in interfaces and in classes.

Use of Interfaces

  • Some typical use cases of interfaces are:
    • You want to allow for the option of having multiple classes implementing a service in different
      ways, but using the same method names.

      • With regular inheritance, you would define such a method in the shared superclass. However, if you cannot model a superclass suitably for inheritance, you need to define an interface and then define this method there.
    • Classes implement interfaces as follows:
      • The interface name is listed in the definition part of the class with the INTERFACES statement. This must be in the PUBLIC SECTION, that is, interfaces can only be implemented publicly.
      • The interface methods must be implemented in the implementation part of the class.
      • The components defined in the interface can be addressed in the implementation part of the class.

Click here to download the presentation and source code for this video.

 

Share this on Social Media

Facebook
Twitter
LinkedIn
Pinterest
WhatsApp

Unit 1 – SAP System Architecture

Unit 2 – Object Navigator, Repository and ABAP Programs

Unit 3 – Transparent tables in the ABAP Dictionary

Unit 4 – Basic ABAP statements, ABAP Structures and ABAP Logical Expressions

Unit 5 – ABAP Data Retrieval

Unit 6 – SAP Analysis Tools

Unit 7 – ABAP Subroutines

Unit 8 – ABAP Events

Unit 9 – ABAP User Interface

Unit 10 – Function Modules, Methods, ALV and BAPI

Unit 11 – Adjusting SAP Standard Software

Unit 12 – ABAP Debugger, Selection Screens, and Table Controls

Unit 13 – ABAP Web Dynpro

Unit 14 – Advanced Topics

Unit 15 – Advanced Topics II

Object Oriented (OO) ABAP

ABAP for SAP HANA (Introduction)

OData and SAP Netweaver Gateway