我有一个Java类,它代表两个元素之间的相关性(典型的POJO):
public class Correlation {
private final String a;
private final String b;
private double correlation;
public Correlation(String a, String b) {
this.a = a;
this.b = b;
}
public double getCorrelation() {
return correlation;
}
public void setCorrelation(double correlation) {
this.correlation = correlation;
}
}
如果要遵循正确的相关逻辑,如果a等于b,则相关值应始终为1。我可以通过更改获取器方法来添加逻辑(忽略a可能为null值的事实):
public double getCorrelation() {
if (a.equals(b)) {
return 1D;
} else {
return correlation;
}
}
让我困扰的是将这个逻辑添加到 getter 方法中,我应该更改方法名称还是仅仅记录文档就足够了?