Difference between class and interface in ABAP Objects
Page 1 of 1
Difference between class and interface in ABAP Objects
Class and interface are interrelated, an interface cannot be implemented without a class
.interface do not have instances. Interface can be implemented in a class using the
statement INTERFACES <interface_name> in the public section of a class. The component of the interface are added automatically in the public section of the class. Now the question comes how do we access the components of the interface ?? Well the components of an interface can be identified as if they are components of the class, through the identifier <interface_name~interface _component >
- Code:
Lets take an example.
INTERFACE my_interface .
METHODS my_interface_method exporting num type i.
ENDINTERFACE.
CLASS interface_class DEFINITION.
INTERFACES my_interface.
ENDCLASS.
CLASS interface_class IMPLEMENTATION.
METHOD my_interface~my_interface_method.
Write:/ num.
ENDMETHOD.
ENDCLASS.
The class must implement the methods of all interfaces implemented in it. The
implementation part of the class must contain a method implementation for each interface
method <imeth>:
METHOD <intf~imeth>.
...
ENDMETHOD.
Note:
Interfaces can be implemented by different classes. Each of these classes is extended by the same set of components. However, the methods of the interface can be implemented differently in each class.
- Code:
INTERFACE common_interface.
METHODS: interface_method.
ENDINTERFACE.
CLASS interface_class1 DEFINITION.
PUBLIC SECTION.
INTERFACES common_interface.
ENDCLASS.
CLASS interface_class1 IMPLEMENTATION.
METHOD common_interface~interface_method. “interface method is implemented as type
1
WRITE:/ ‘ METHODS IMPLEMENTATION TYPE 1
ENDMETHOD.
ENDCLASS.
CLASS interface_class2 DEFINITION.
PUBLIC SECTION.
INTERFACES common_interface.
ENDCLASS.
CLASS interface_class2 IMPLEMENTATION.
METHOD common_interface~interface_method. “Interface method is implemented astype2
WRITE:/ ‘ METHODS IMPLEMENTATION TYPE 2
ENDMETHOD.
ENDCLASS
Uma_ABAP- Posts : 56
Join date : 2012-03-31
Similar topics
» Introduction to interface in ABAP objects
» Polymorphism using interface in ABAP Objects
» Creating Interface in ABAP Objects with example
» Interface reference and component access in ABAP Objects
» Introduction to class in ABAP Objects
» Polymorphism using interface in ABAP Objects
» Creating Interface in ABAP Objects with example
» Interface reference and component access in ABAP Objects
» Introduction to class in ABAP Objects
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Mon Aug 20, 2012 4:37 pm by Admin
» Difference between Type and Like
Thu Jun 07, 2012 2:40 pm by Admin
» How to handle table control fields in Module Pool program?
Wed May 09, 2012 2:41 am by govind
» Three tables inner join in SAP
Thu May 03, 2012 4:47 pm by Uma_ABAP
» Creating table type in ABAP
Sat Apr 28, 2012 9:03 pm by Uma_ABAP
» Creating user defined types and structures in ABAP
Sat Apr 28, 2012 8:55 pm by Uma_ABAP
» Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP
Fri Apr 27, 2012 11:00 am by Admin
» Copy Custom PF-Status from Standard program to Custom Program in ALV
Thu Apr 26, 2012 9:52 pm by Uma_ABAP
» Calculate/find number of working days between two dates in SAP
Tue Apr 24, 2012 2:06 pm by Uma_ABAP