Last active
December 12, 2015 02:49
-
-
Save grimrose/4702398 to your computer and use it in GitHub Desktop.
こんな感じのクラスをリファクタリングには?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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