Skip to content

Instantly share code, notes, and snippets.

@grimrose
Last active December 12, 2015 02:49
Show Gist options
  • Save grimrose/4702398 to your computer and use it in GitHub Desktop.
Save grimrose/4702398 to your computer and use it in GitHub Desktop.
こんな感じのクラスをリファクタリングには?
public class EmployeeBean {
private boolean forManagementMode;
public String getFullName(String userCode) {
Employee employee = findBy(userCode);
if (employee.middleName == null) {
return employee.lastName + " " + employee.firstName;
}
return employee.lastName + " " + employee.middleName + " " + employee.firstName;
}
private Employee findBy(String userCode) {
User user = findUserBy(userCode);
if (user == null) throw new IllegalArgumentException("user not found.");
Employee employee = Employee.findBy(user.userId);
if (employee == null) throw new IllegalArgumentException("employee not found.");
return employee;
}
private User findUserBy(String userCode) {
User user = User.findBy(userCode);
if (user == null) throw new IllegalArgumentException("user not found.");
if (isForManagementMode()) {
if (user.activateDate == null) return null;
if (user.activateDate.compareTo(new Date()) < 0) return null;
}
return user;
}
public boolean isForManagementMode() {
return forManagementMode;
}
public void setForManagementMode(boolean forManagementMode) {
this.forManagementMode = forManagementMode;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment