01-22-2008 1:14 PM
hi gurus
can anyone explain me what is interface
tahnk you
regards
kals.
01-22-2008 1:16 PM
Hi Kalyan,
You should be more specific: An interface can mean a connection between two systems or can also be used in the OO-context.
Regards,
John.
01-22-2008 1:22 PM
hi
Interfaces are independent structures that allow you to enhance the class-specific public points of contact by implementing them in classes.
Interfaces can be defined globally in the R/3 repository or locally in ABAP program
Can define exactly same components in Interfaces as in Classes
Unlike classes, Interfaces do not have instances, instead they are implemented by classes
Implemented using INTERFACES statement in the declaration part of the class
INTERFACES statement must be included in the PUBLIC SECTION of the class
Different classes that implement the same interface can all be addressed in the same way.
Interface references allow users to address different classes in the same manner.
Interfaces can also be nested.
Interfaces are the basis for polymorphism in classes, because they allow a single interface method to behave differently in different classes.
If an interface is implemented in the class, the interface components are added in the public section of the class.
A component comp of an interface intf, implemented in a class, becomes a fully-fledged member of that class, with the name intf~comp.
Classes that implement interfaces must implement all of their methods.
METHOD intf~meth.
ENDMETHOD.
Interfaces allow you to use different classes in a uniform way (polymorphism).
Interface References
Creating Interface Reference Variables
DATA obj TYPE REF TO intf.
Using this reference variable, you can access any of the components defined in the interface
Nested Interfaces
Interface can include one or more interfaces as components, which can contain interfaces themselves.
Compound Interface : It includes other interface as its component.
Elementary Interface : It does not include any interface as a component.
All interface components of a compound interface have the same level
A component interface exists only once even if it is used once more as a component of another component interface.
Aliases : It can be used to assign alias names to the components of component interfaces, thus making them visible within the interface definition.
ALIASES <alias name> FOR intf~comp.
Where, intf = interface name and comp = Component name
Accessing Objects using Interface References
It is also possible to directly generate an object to which the interface reference
variable points initially. In this case, the TYPE addition of the statement CREATE OBJECT must be used to specify a class that implements the interface. CREATE OBJECT iref TYPE class.
If the interface intf contains an attribute attr and an instance method meth, you can address them as follows:
Using the class reference variable:
Accessing an attribute attr: cref->intf~attr
Calling a method meth: CALL METHOD cref->intf~meth
Using the interface reference variable:
Accessing an attribute attr: iref->attr
Calling a method meth: CALL METHOD iref->meth
Accessing Static Components of Interfaces
Use the name of the interface to access constants within an interface.
Accessing a constant const: intf=>const.
To access the other static components of an interface, use an object reference or the class class that is implementing the interface.
Accessing a static attribute attr: class=>intf~attr.
Calling a static method meth: CALL METHOD class=>intf~meth.