02-01-2005 10:29 AM
Hello,
I'd like to know what sense it makes to define static methods in an interface.
My understanding is, that an interface can only be used with an instance of a class implementing that interface. So I always need to have an instance and thus, static methods are not needed.
But ABAP-OO (in contrast to Java, for example) allows that, so maybe there is some need for that?
Thanks for your help, best regards,
Timo Wolf.
02-01-2005 10:52 AM
Hi,
As you know that static methods are not instance- specific. Hence when a class implements an interface, the methods defined as static do not require an instance-specific call. Rather they are called as CLASSNAME=>INTREFACE_NAME~STATIC_METHOD_NAME. You do not need an instance to access them.
The only purpose of declaring a method as STATIC in interface definition is to create an agreement that a particular method will not depend on an instance to work. When a class implements the interface, calls to this method will be as mentioned above.
<b>
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>
</b>
Hope this helps.
Regards
Message was edited by: Shehryar Khan
Message was edited by: Shehryar Khan