[VW] refactor/extract method to component

[VW] refactor/extract method to component

Post by asko » Sat, 02 Dec 2006 05:25:00


What does the following menu item in the refactory browser do?
Refactor>Extract Method to Component
I cannot find documentation for it. I have tried and don''t see what is
happening.

Thanks,
Aik-Siong Koh
 
 
 

[VW] refactor/extract method to component

Post by Niall Ros » Sun, 03 Dec 2006 00:02:57

Dear Koh


It is like 'Extract method' but instead of extracting the selected code to
the same class it extracts it to another class - the class of a variable of
the method - and the original method calls the new method on that variable,
not on self. The idea is that if, as a system develops, you find you have
code like

SomeClass>>someMethod
...
myFunction tasks do:
[:each | (myFunction shouldHandle: each)
ifTrue: [myFunction handle: each]].
...

it can be extracted to

AbstractFunction>>handleTasks
self tasks do:
[:each | self shouldHandle: each)
ifTrue: [self handle: each]].

called in

SomeClass>>someMethod
...
myFunction handleTasks.
...

On invoking it, you get a dialog asking which variable is the target. On
selecting one, you will be asked to choose a suitable class from a list
which the refactoring guesses represent possible classes for instances held
in that variable. You can add your own class to the list. The rewriting
replaces direct references to the instVar or parameter chosen with 'self' .
It will also replace references to self in the original with some accessor
for which the user is prompted if required, etc.

Yours faithfully
Niall Ross