Implementation of Interface Inside Class in SAP ABAP

INTERFACE interface_name

Explanation: First we create a class inside that we use above syntax to implement interface. here interface_name means name of interface.

Implementing method of an interface inside class in SAP ABAP

METHOD interface_name~interface_method_name
satements
ENDMETHOD

Explanation: we use METHOD keyword to implement method of interface inside implementing class, interface_name~interface_method_name refers to the name of interface along with method name declare in interface.

SAP ABAP | Interfaces

ABAP(Advanced Business Application Programming) is an object-oriented programming language that supports many oops concepts like other programming languages. It supports all the four pillars of oops i.e. Inheritance, Polymorphism, Abstraction, and Encapsulation. The interface is one of the oops concepts that ABAP supports and it plays a very important role in implementing all these oops concepts.

Table of Content

  • What is Interface in SAP ABAP
  • Syntax for Creating an Interface in SAP ABAP
  • Implementation of Interface Inside Class in SAP ABAP
  • Example Program
  • Program Execution – Creating Objects ‘object1’ and ‘object2’
  • Benefits and Application of Interface in SAP ABAP

Similar Reads

What is Interface in SAP ABAP

The interface in SAP ABAP is different from the class, it can not have any implementation like the class. It defines a set of method declarations that a class must implement without providing any implementation detail of that method. Interface helps in achieving multiple inheritance. Multiple inheritance can be defined as a class can inherit multiple interfaces. Due to Inheritance interface provides a base for polymorphism because the method declared in the interface behaves differently in different classes. Like class Interface can be defined locally or globally in the ABAP programming language....

Syntax for Creating an Interface in SAP ABAP

Syntax...

Implementation of Interface Inside Class in SAP ABAP

INTERFACE interface_name...

Example Program

Here is an example of interface and a class implementing that interface....

Program Execution – Creating Objects ‘object1’ and ‘object2’

Creating object 1 and calling add method...

Benefits and Application of Interface in SAP ABAP

Same Method but Different Functionality: The method declare in interface can have different functionality when use in different class this is because we can not implement method in interface we can only declare that method. class implement or use that function according to their need. It also group common functionality which makes a program more readable. Multiple Inheritance: Inheritance support multiple inheritance, which means two or more class have same methods name but different functionality. A class can implement multiple interfaces, inherit the method declare in the interface whereas a class support only single inheritance. Polymorphism: It is a concept of oops, polymorphism is derived from a geek word poly means many and morph means form. The main purpose of inheritance is to achieve run time polymorphism. Inheritance provide a base for polymorphism as a single method declare in interface can be used by different class with different functionality....