Interface reference and component access in ABAP Objects

Go down

Interface reference and component access in ABAP Objects

Post  Uma_ABAP on Sun Apr 01, 2012 1:22 pm


As we know that before creation of any object it must have a reference to a class, similarly an interface can also have a reference. But we know interface cannot be instantiated so why do we need a reference for it?? The interface reference is used from a totally different point of view, an interface reference is used to access the interface components that has been implemented differently in different class. We will elaborate this in the next article. An interface reference can be created similar to object reference.

DATA: interface_ref TYPE REF TO my_interface.

To create an object of the class <class>, you must first have declared a reference variable <cref> with reference to the class. If the class <class> implements an interface <intf>, you can use the following assignment between the class reference variable <cref> and an interface reference <iref> to make the interface reference in <iref> point to the same object as the class reference in <cref>:

<iref> = <cref>

If the interface <intf> contains an instance attribute <attr> and an instance method <meth>, you can address the interface components as follows:

Using the class reference variable <cref>:
• To access an attribute <attr>: <cref>-><intf~attr>
• To call a method <meth>: CALL METHOD <cref>-><intf~meth>
Using the interface reference variable <iref>:

• To access an attribute <attr>: < iref>-><attr>
• To call a method <meth>: CALL METHOD <iref>-><meth>


Uma_ABAP

Posts : 56
Join date : 2012-03-31

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum