我需要降低该模型的圈复杂度,因为它有26个,这是设置和获取方法的常规类
public class DetailRecord {
private int lengthReference1;
private int lengthReference2;
private int lengthPayersNit;
private int lengthTransactionAmount;
private String recordType;
private String payersNit;
private String payersName;
private String payersAccountBank;
private String accountNumberToBeDebited;
private String transactionType;
private String transactionAmount;
private String referenceOne;
private String referenceTwo;
private String expirationDateOrApplicationDate;
private String billedPeriods;
private String cycle;
private String reserved;
private String validationNit;
private String encabezadoTotal;
public DetailRecord() {
lengthReference1 = 30;
lengthReference2 = 30;
lengthPayersNit = 13;
lengthTransactionAmount = 17;
recordType = "6";
payersName = " ";
}
public int getLengthReference1() {
return lengthReference1;
}
public int getLengthReference2() {
return lengthReference2;
}
public int getLengthPayersNit() {
return lengthPayersNit;
}
public int getLengthTransactionAmount() {
return lengthTransactionAmount;
}
public String getRecordType() {
return recordType;
}
public String getPayersName() {
return payersName;
}
public String getPayersAccountBank() {
return payersAccountBank;
}
}
我如何降低圈复杂度?也许使用建造者,或者我还能做什么?提取类还是创建接口?
答案 0 :(得分:0)
您可以使用组合,将此类分成多个类并分离不相关的事物。这样,您将拥有多个类,从而使其更易于维护和扩展,并降低了圈复杂度。
答案 1 :(得分:0)
我使用工厂方法降低了环吡菌酰胺的复杂度,
$ cat chris_smith.txt
Component: McAfee Agent
AgentMode: 1
Version: 5.0.6.491
GUID: f0bcc8de-1aa6-00a4-01b9-00505af06706
TenantId: N/A
LogLocation: /var/McAfee/agent/logs
InstallLocation: /opt/McAfee/agent
CryptoMode: 0
DataLocation: /var/McAfee/agent
EpoServerList: 10.0.25.15|epo1|epo1.example.com|10.0.25.20|epo2|epo2.example.com
EpoPortList: 443
EpoServerLastUsed: 10.0.25.15
LastASCTime: N/A
LastPolicyUpdateTime: 0
EpoVersion: 5.3.1
Component: McAfee Agent
$
}