Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

what is interface in oops abap

Former Member
0 Likes
956

hi experts.

what is interface in oops abap.

thanks.

subhasis

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
583

Like classes, you can define interfaces either globally in the R/3 Repository or locally in an ABAP program. For information about how to define local interfaces, refer to the Class Builder section of the ABAP Workbench Tools documentation. The definition of a local interface <intf> is enclosed in the statements:

INTERFACE <intf>.

...

ENDINTERFACE.

The definition contains the declaration for all components (attributes, methods, events) of the interface. You can define the same components in an interface as in a class. The components of interfaces do not have to be assigned individually to a visibility section, since they automatically belong to the public section of the class in which the interface is implemented. Interfaces do not have an implementation part, since their methods are implemented in the class that implements the interface.

<b>Implementing Interfaces</b>

Unlike classes, interfaces do not have instances. Instead, interfaces are implemented by classes. To implement an interface in a class, use the statement

INTERFACES <intf>.

in the declaration part of the class. This statement may only appear in the public section of the class.

When you implement an interface in a class, the components of the interface are added to the other components in the public section. A component <icomp> of an interface <intf> can be addressed as though it were a member of the class under the name <intf~icomp>.

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.

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.

Interfaces allow you to use different classes in a uniform way using interface references (polymorphism). For example, interfaces that are implemented in different classes extend the public scope of each class by the same set of components. If a class does not have any class-specific public components, the interfaces define the entire public face of the class.

<b>

Addressing Objects Using Interface References</b>

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>

As far as the static components of interfaces are concerned, you can only use the interface name to access constants:

Addressing a constant <const>: < intf>=><const>

For all other static components of an interface, you can only use object references or the class <class> that implements the interface:

Addressing a static attribute <attr>: < class>=><intf~attr>

Calling a static method <meth>: CALL METHOD <class>=><intf~meth>

1 REPLY 1
Read only

Former Member
0 Likes
584

Like classes, you can define interfaces either globally in the R/3 Repository or locally in an ABAP program. For information about how to define local interfaces, refer to the Class Builder section of the ABAP Workbench Tools documentation. The definition of a local interface <intf> is enclosed in the statements:

INTERFACE <intf>.

...

ENDINTERFACE.

The definition contains the declaration for all components (attributes, methods, events) of the interface. You can define the same components in an interface as in a class. The components of interfaces do not have to be assigned individually to a visibility section, since they automatically belong to the public section of the class in which the interface is implemented. Interfaces do not have an implementation part, since their methods are implemented in the class that implements the interface.

<b>Implementing Interfaces</b>

Unlike classes, interfaces do not have instances. Instead, interfaces are implemented by classes. To implement an interface in a class, use the statement

INTERFACES <intf>.

in the declaration part of the class. This statement may only appear in the public section of the class.

When you implement an interface in a class, the components of the interface are added to the other components in the public section. A component <icomp> of an interface <intf> can be addressed as though it were a member of the class under the name <intf~icomp>.

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.

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.

Interfaces allow you to use different classes in a uniform way using interface references (polymorphism). For example, interfaces that are implemented in different classes extend the public scope of each class by the same set of components. If a class does not have any class-specific public components, the interfaces define the entire public face of the class.

<b>

Addressing Objects Using Interface References</b>

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>

As far as the static components of interfaces are concerned, you can only use the interface name to access constants:

Addressing a constant <const>: < intf>=><const>

For all other static components of an interface, you can only use object references or the class <class> that implements the interface:

Addressing a static attribute <attr>: < class>=><intf~attr>

Calling a static method <meth>: CALL METHOD <class>=><intf~meth>