Move Method

http://www.refactoring.com/catalog/moveMethod.html


Also described on page 142 of MartinFowler's RefactoringImprovingTheDesignOfExistingCode:
"A method is, or will be, using or used by more features of another class than the class on which it is defined.
"Create a new method with a similar body in the class it uses most. Either turn the old method into a simple delegation, or remove it altogether."


While ReFactor-ing, you discover a method that is very tightly bound to another class, but not to its own.

Therefore, move the method.

Example.

  View>>...
	....
	area := bounds bottom - bounds top * (bounds right - bounds left).
	....

becomes:

  Rectangle>>area
	^self bottom - self top * (self right . self left)

View>>... .... area := bounds area. ....

You may be able to use this refactoring any time you see two or more messages in a single method going to an object other than self.


What do you do when you'd like to MoveMethod or MoveField, but you are not able to change the desired destination class because it is in SomebodyElsesFramework, or due to restrictive configuration management policies? See ForeignMethod and IntroduceLocalExtension.


See also WithBlockCodeSmell

[CategoryRefactoring]

EditText of this page (last edited August 26, 2002) or FindPage with title or text search