Technical Articles
ABAP OO – extract Interface / using SE24 refactoring assistant
A looong time ago, when I was still in school, eclipse was new (and only for Java programming) and a cool thing it could do was “extract interface”: You would code a class, click that button and an interface would be created.
In ABAP, I don’t think, there is such a thing (or is there?). Also, in the past I have not cared much for interfaces, although I kind of know, it’s good to have them (e.g. for making things easy with ABAP unit and also good OO design (“always program against an interface” )).
So I have a class and no interface, but I rather have a class, implementing an interface.
Here is what I do:
1. SE24 create the interface (just name and description)
2. SE24 assign it to my class, activate.
3. Call up utilities-> Refactoring -> Refactoring assistant
4. Drag&drop public methods from the class to the interface.
5. Save + activate.
Done
So how about you?
– did you know the SE24 refactoring assistant?
– is there something similar in AdT?
– don’t you ever need something like that, as always create an interface up front?
best
Joachim
PS: I think this could be a text-only blog, but as I made some screenshots, I’ll share them here:
SE24 – call the refactoring assistant
use the refactoring assistant
SE24: use the refactoring assistant
Hi Joachim,
This is really easy in ADT. All you have to do is add the INTERFACES statement in your class and add the interface you want to create. Then use the Quick Assist (Ctrl+1) to create the interface. Then if you have methods that you want to move from the class to the interface, just put your cursor on the method name and use Ctrl+1 again and choose the option to pull the method up to the interface. This will move the method definition to the interface and create an alias for the method name in your class.
-Scott
Ah, thanks a lot Scott Lawton , I'll surely give that a try next time!