Moving a method between classes

There are times that a specific method in a class suffers from feature envy. It will call a lot of messages in another class and access the other class's fields. When this occurs, you should consider moving the method to the other class.

This implementation allows you to move a method to a class that is included in the parameter list.

To move a method right click on the method in the class diagram. Select Method Refactorings and then Move method from the popup menu. In the dialog box, pick which parameter should be used as the destination class.>

A class cannot be moved when it accesses package level methods in the current class and the destination is in another class. It also cannot be moved when it sends private messages. The final reason that a class cannot be moved is if it accesses private variables in the current class, and the current class does not provide getters and setters for that variable.


Last Modified: 30 October 2003