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

Move methods from interface to interface

Former Member
0 Likes
1,610

Hello everbody,

is there any possibility to move methods from one interface to a other (not copy)?

This is my case:

I have a implementented class which includes some interfaces.

Now, I want to move some methods of one interface to a new one.

The new interface will be also bound in the implemented class.

Is this possible?

What happens with the implementations of the methods in the exesting class?

Regards

Christian

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,233

Hello Christian

Yes, it is possible to move methods from one interface to another using the <b>Refactoring Assistant</b>.

Here is the <b>scenario </b>followed by the procedure:

- ZIF_INTERFACE1 with method METHOD_1

- ZIF_INTERFACE2 with method METHOD_2

- ZCL_CLASS implementing both interfaces with different coding in the interface methods

<b>Aim</b>: Move ZIF_INTERFACE2METHOD_2 to ZIF_INTERFACE1METHOD_2

Steps for refactoring:

1. Delete method METHOD_2 from interface ZIF_INTERFACE_2 (and activate).

2. SE80 (or SE24): Open class ZCL_CLASS in <i>Change </i>mode -> popup appears asking whether you want to adjust class? -> Confirm (Yes).

3. Next popup asking whether ZIF_INTERFACE2~METHOD_2 should be deleted or saved as local method -> choose <b>local method</b>, name METHOD_2 (and activate)

4. Choose: Menu Utilities -> Refactoring Assistant => expand the hierarchy and <b>drag&drop (!!!

Regards

Uwe

7 REPLIES 7
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,233

Hi,

IN SE24 there is an option under the menu <b>"Utilites->Refactoring Assistant".</b>

But <b>your requirement of</b> moving a method from One INTERFACE to Another is <b>NOT possible</b> as this is not technically correct, but IF INTERFACE2 INHERITS INTERFACE1, then this is possible.

But Moving one method of an interface to another interface is not possible if these interfaces are not related to each other.

Regards,

Sesh

Read only

Former Member
0 Likes
1,233

Thank you Sesh.

I think I must search a other solution.

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,234

Hello Christian

Yes, it is possible to move methods from one interface to another using the <b>Refactoring Assistant</b>.

Here is the <b>scenario </b>followed by the procedure:

- ZIF_INTERFACE1 with method METHOD_1

- ZIF_INTERFACE2 with method METHOD_2

- ZCL_CLASS implementing both interfaces with different coding in the interface methods

<b>Aim</b>: Move ZIF_INTERFACE2METHOD_2 to ZIF_INTERFACE1METHOD_2

Steps for refactoring:

1. Delete method METHOD_2 from interface ZIF_INTERFACE_2 (and activate).

2. SE80 (or SE24): Open class ZCL_CLASS in <i>Change </i>mode -> popup appears asking whether you want to adjust class? -> Confirm (Yes).

3. Next popup asking whether ZIF_INTERFACE2~METHOD_2 should be deleted or saved as local method -> choose <b>local method</b>, name METHOD_2 (and activate)

4. Choose: Menu Utilities -> Refactoring Assistant => expand the hierarchy and <b>drag&drop (!!!

Regards

Uwe

Read only

0 Likes
1,233

Hi Uwe,

wow. Great solution. I need to read up more on this.

Cheers

Graham

Read only

0 Likes
1,233

Hello Graham

I used to be a scientist (originally studied Biochemistry -> see short bio on business card). In science it is extremely difficult to prove that something is not possible or does not exist. You rarely find publications trying to do that.

Therefore, if somebody (here in the forums) says that something is not possible I get excited just for the sake of refuting this opinion. In most cases such negative statements are due to

- lack of knowledge
- lack of imagination
- a poor snapshot

It took me just two trials to find the right way. I have not yet used the refactoring assistant that much but I believe that any reasonable refactoring will be supported by this assistant.

Apparently many people believe there is something special about ABAP-OO which is not the case. The major OO-principles can all be applied to ABAP-OO as to any other OO-language (like Java).

Regards

Uwe

Read only

0 Likes
1,233

Scenario : Moving a method from one interface to another ist not working as described in the answer.

dragging the saved local method will ad another method to the existing interface instead of replacing the implementation with the saved implementation. It would add more and more methods to the 'new' interface .

Even worth: Did not work at all, as the saved methods did not copy any of the parameters , saving is wrong for me.

unfortunately i will give up. (task was: integrating one interface into another -> therefore moving all implementations form one into the new one. Wanted to move most component of a special interface into a more general one and only keep the more special features in the existing one )

Another comment: Why don't try this: Because before agreeing to adjust, you do not know that there will be the option for a local copy : In the Info before it says, it will just delete the method and therefore the implementation would be lost . There i stopped.

Intuitively i expected, that i keep the methods of the interfaces and will have the option to also drag and drop methods of included interfaces : This action then would mean to move the implementation instead of adding as new method like it is, when i drag a method of the class (what is a very nice feature)

Read only

Former Member
0 Likes
1,233

I have try it and it works!

Thank you very much Uwe!