Refactoring "hide delegate" as procedure available?

Answered

Is there a procedure in IntelliJ IDEA with which you can apply the refactoring "hide delegate" (see https://refactoring.guru/hide-delegate)?

(At least I couldn't find one in the refactoring menu.)

0
2 comments

Hello, 

Here is the code sample:

class Employee {
Department department;

public Employee(final Department department) {
this.department = department;
}

public Department getDepartment() {
return department;
}
}

class Department{
Employee manager;

public Department(final Employee manager) {
this.manager = manager;
}

Employee getManager() {
return manager;
}
}

class Sample {
Employee john;
Employee johnsManager = john.getDepartment().getManager();
}

You may extract the method getManager in Sample class (CMD + Alt + M with cursor at getManager method) and move it to Employee class with Refactor | Move Instance method (F6).

 

 

1

That's exactly what I was looking for - thank you very much!

0

Please sign in to leave a comment.