2007 Apr 27 7:18 AM
hi guru
please tell me what is interface in oops.
thanks
subhasis
2007 Apr 27 7:39 AM
Please the search functionality of this forum. Because this question is certainly asked before.
But :
An interface is a class with only a definition (methods). The implementation is done by another class (can be a ZCL - customer class) where you can add the interface class as interface in the properties.
regards,
Hans
Please reward all helpful answers !!!!!
2007 Apr 27 8:46 AM
An interface is a collection of declaration of methods. These methods do not contain an implementation in the interface. The implementation is provided by the respective class that implements the interface. Thus, a single declaration of a method in an interface is usable by different classes to provide separate implementations.
read more about abap objects in the abap help and you will come to know in details.
regards,
Priyank
2007 Apr 27 9:46 AM
Hello!!!
check out the example of interface :-
This program will show simple use of an interface with its own data and methods and how it is implemented in a class. It will also show that there can be methods of same name for an interface and the class implementing the interface.
This program contains an interface I1 with attribute : NUM an method : METH1.
This interface is implemented in a class : C1 which also has its own method METH1.
An object OREF is created from class C1 and both the methods METH1 , one for class and another for interface is called using the object.
report ysubdel .
interface i1.
data : num type i .
methods : meth1.
endinterface.
class c1 definition.
public section.
methods : meth1. class C1s own method
interfaces : i1.
endclass.
class c1 implementation.
method : meth1.
write:/5 'I am meth1 in c1'.
endmethod.
method i1~meth1.
write:/5 'I am meth1 from i1'.
endmethod.
endclass.
start-of-selection.
data : oref type ref to c1.
create object oref.
write:/5 oref->i1~num.
call method oref->meth1.
call method oref->i1~meth1.
0
I am meth1 in c1
I am meth1 from i1
<b>Reward points if helpful</b>
Thanks in advance,
Sachin
2007 Apr 27 11:46 AM
Hi Subhasis,
1. Interfaces are defined independently of classes.
2. They can contain declarations for elements such as attributes and methods.
3. Interfaces are implemented by classes
4. The classes then have a uniform external point of contact. They must provide all
of the functions of the interface by implementing its methods.
5. In a program, you can create reference variables with reference to interfaces.
6. However, you cannot instantiate an interface.
7. Interface references can, however, point to objects of different classes.
<b>plz reward points if helpful or if it solves ur query.</b>
Thanks
Chinmay