我发现了一些出色的代码,其中包含 30 多个参数给一个方法(我记错了)。该实现包含 500 多行带有if/then/else和switch块的行。
如何以干净的方式重构它?您对此有何建议?
很多实现都遍布整个应用程序,并且都推送这些参数。
问题方法:
public static User findUser (
String userCode, String lastName, String firstName,
String alternativeLastName, String sex, int day, int month, int year,
String locationParameter, String locationInfo,
Id groupId, Id organizationId, Id orderId,
Id orderGroupId, Id orderOrganizationId,
List<Id> groupIds, List<Id> organizationIds,
List<Id> orderIds, List<Id> orderGroupIds,
List<Id> orderOrganizationIds,
String timeRange, Long daysAgo,
Date dateFrom, Date dateUntil,
CodingMap codingMap, List<String> languageList, String visitType,
Account account, List<Group> accountGroups,
Organization accountOrganization, Profile profile,
AccessProfile accessProfile, Locale locale, int maxResults,
long newTimeRange, long minimumTimeRange,
boolean hideUserWithoutName, boolean withOrderInfo, boolean withVisitInfo,
boolean orderEntryAvailable,
boolean hideDiscontinuedResults, boolean checkPatientAccessRights, boolean searchForCopies,
boolean inOrderEntry, boolean allPatientCodes,
boolean addPatientCharacteristics, boolean showSpeciesColumn,
boolean patientDefinedWithPrivacyLevel,
boolean excludePatientsWithoutCodeInSelectedCodingSystem
) throws CompanyException {
...
}
像这样到处使用:
User.findUser(member.getCode(), context.lastName, context.firstName,
context.alternativeLastName, context.sex,
context.birthDate.getDay(), context.birthDate.getMonth(),
context.birthDate.getYear(),
context.locationParameter, context.locationInfo,
null, null, null, null, null, null, null, null, null, null,
session.timeRange(), session.daysAgo(), session.dateFrom(),
session.dateUntil(),
order.codingMap(), order.languageList(), member.visitType(),
null, null, null, null, null, locale, 25, 1000L,200L,
session.point.booleanValue(), session.infobooleanValue(), false,
true, true, true, true, true, true, true, false, false, false);