2 comments
Comment actions Permalink

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
Comment actions Permalink

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

0

Please sign in to leave a comment.