Nested interfaces and abstract methods
Consider the following design:
interface ZIF_INTERFACE_A. methods METHOD_A. endinterface. interface ZIF_INTERFACE_B. interfaces ZIF_INTERFACE_A. methods METHOD_B. endinterface. class CLASS_A_B definition abstract. public section. interfaces ZIF_INTERFACE_B abstract methods METHOD_B. interfaces ZIF_INTERFACE_A abstract methods METHOD_A. methods METHOD_C. endclass. class CLASS_A_B implementation. method METHOD_C. endmethod. endclass.
When trying to implement this design, the syntax check is giving me an error:
The method "METHOD_A" was declared as not ABSTRACT in a previous INTERFACES statement.
If I implement the design with Java (either using a public nested interface, or using interface inheritance) there is no problem declaring both the methods METHOD_A and METHOD_B as abstract in the CLASS_A_B class.
So it seems to me this might be a bug in the ABAP Objects implementation. Or perhaps I am missing something else here? Does anyone have any suggestions?
Suhas Saha replied
When you include an IF in another IF both of them will exist on the same level, there is no concept of hierarchy. So when you add interface ZIF_B in the implementing class ZCL_A_B, the interface ZIF_A is also "included" in the relationship with the class ZCL_A_B implicitly.
Just try to activate the code below & you'll get the error: "Implementation missing for method zif_interface_a~method_a":
CLASS class_a_b DEFINITION ABSTRACT. PUBLIC SECTION. * INTERFACES zif_interface_a * ABSTRACT METHODS method_a. INTERFACES zif_interface_b ABSTRACT METHODS: method_b. METHODS method_c. ENDCLASS. "CLASS_A_B DEFINITION
CLASS class_a_b DEFINITION ABSTRACT. PUBLIC SECTION. INTERFACES zif_interface_b ABSTRACT METHODS method_b. INTERFACES zif_interface_a ABSTRACT METHODS method_a. METHODS method_c. ENDCLASS. "CLASS_A_B DEFINITION
So when the compiler is trying to compile your code it encounter implementation of ZIF_INTERFACE_B it finds that the "included interface" method ZIF_INTERFACE_Amethod_a is not abstract. So when you declare ZIF_INTERFACE_Amethod_a as "abstract" in the next line the compiler throws this error.
So you need to define ZIF_INTERFACE_A~method_a as abstract, before defining ZIF_INTERFACE_B. Like this:
CLASS class_a_b DEFINITION ABSTRACT. PUBLIC SECTION. INTERFACES zif_interface_a ABSTRACT METHODS method_a. INTERFACES zif_interface_b ABSTRACT METHODS method_b. METHODS method_c. ENDCLASS. "CLASS_A_B DEFINITION
In this case the compiler treats method_a as abstract while checking ZIF_INTERFACE_B. Hence it doesn't throw any error.
Hope i'm clear.
PS: Whenever i face any problem while creating local classes, i create a dummy class in the class builder to check