Java Reference
In-Depth Information
As before, choose whether you want to extract a new superclass or to rename the
original class, and then select the methods you wish to define in the superclass. If
you want the method to be abstract, select the checkbox next to the method
name. In this case, the implementation remains in the existing class. If the box is
left deselected, the implementation is moved into the new superclass. JavaDoc for
concrete methods is moved along with the methods, but you need to tell IDEA
how to handle the JavaDoc for abstract methods by selecting one of the JavaDoc
options as in the Extract Interface refactoring.
When you click OK , IDEA attempts the refactoring and alerts you to any prob-
lems it encounters. When you move methods to the superclass, you need to be
sure that you've resolved any dependencies between them. For example, if
method A calls method B or uses field C , these must be moved as well. IDEA calls
your attention to dependencies by highlighting any unselected members that are
dependencies of selected ones. If you ignore them, you get an error message. You
must keep the methods with the dependencies where they were or move the
dependencies over them.
The refactoring creates or renames the new superclass for you and changes
your existing class to extend it. Any non-abstract methods created in the super-
class are removed from the original class. When the refactoring is complete,
you're given the option to automatically find references to the existing class and
replace them with reference to the more generic superclass type.
Rearranging method hierarchies: pulling members up
and pushing members down
IDEA makes it easy to restructure your inheritance relationships by allowing you
to move methods and fields up and down the hierarchy. This means you can go
back to the example and move additional methods into the interface or super-
type. Or, from the base class or interface, you can move them back down into the
implementation classes.
The commands Refactor | Pull Members Up and Refactor | Push Members
Down work similarly to the other hierarchical structure refactoring operations
we've been examining. You specify which method to push or pull. When you're
pushing members down from supertype classes, you can specify that the methods
should not be removed from the superclass but made abstract instead. Likewise,
when pulling up into a superclass, you can make the new methods abstract if you
wish, just as you saw with Extract Superclass .
 
 
 
 
 
 
Search WWH ::




Custom Search