Refactoring Move Method

On the refactoring list I brought up the problem where moving a non-static method was dificult. I got the following response from one of the participants, so I thought I would share it. Perhaps it offers a reasonable way to do move method within IDEA.

You must remember that in Smalltalk every message is potentially
polymorphic, not necessarily even with respect to the inheritance
hierarchy. So here's what the RB does...

Move method moves the method body to another class. That class has
to be available through an instance variable of the original class or
a parameter (or basically any visible variable). The method body is
checked for things that are only accessible in the original class
(self references, instance variable reference). If there are self
references, self must be passed as an argument to the new method. If
there are instance variable references, accessors must exist or be
created. The new method is compiled in the new class. The old method
body is replaced by a "forwarder" that simply calls the new method.
This maintains the interface of the original class while moving the
functionality. Polymorphism still works. That's the whole refactoring.

Now if the user wants to get rid of forwards (quite common), they can
perform the inline method refactoring on all of the senders. If the
original method is called polymorphically, this won't be doable.


Please sign in to leave a comment.