Refactoring Request: "Pull Members Out"

How about adding a refactoring that will extract selected class members (specifically variables, but why not methods as well) into a new standalone class, and replace all accesses of those variables with new get/set methods on the new class?

For example:

class Foo
{
private int x1;
private int x2;
private String x3;

private int foo()
{
return x1 *2;
}
}

run the refactoring, which create new class, Bar:

class Foo
{
private Bar bar;

private int foo()
{
return bar.getX1() *2;
}
}

class Bar
{
private int x1;
private int x2;
private String x3;

public int getX1()
{
.....
}

.
.
.
}


Is this can already be done, somebody please point me in the right direction.

Nick

3 comments

Could be called "Extract Data Object"

or you could extend the existing "Move" refactoring to allow variables to moved to a new class.

0

This refactoring is available as part of the Refactor-J plugin, a recommended companion product for IDEA. We call it "Extract Class", and it is only one of twenty refactorings and code assists in the product. Refactor-J is available at http://www.sixthandredriver.com, with a single user price of $49.

Sixth and Red River Software
"Code with Grace and Verve"

Message was edited by:
Sixth and Red River Software

0

Looks good. But probably SixRR's introduce parameter object can already do this?

0

Please sign in to leave a comment.