我发现一些辉煌的代码与30多个参数给一个方法(我失去了计数)。 如果/ then/else和开关块的实现包含超过500行。重构帮助需要 - 与许多参数的方法
这怎么可能在一个干净的方式重构? 你的建议是什么?
大量的实现遍布整个应用程序,并全部推送这些参数。
问题的方法:
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);
Ø...,M ...摹...... – assylias
我的建议是** **运行。 –
重构?我会称之为'重写'代码:D – Juvanis