I have a Java class which represents the correlation between two elements (typical 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;
}
}
To follow the correct correlation logic if a equals b then the correlation value should be ALWAYS 1.
I could add the logic altering the getter method (ignore the fact of the possible null value for a):
public double getCorrelation() {
if (a.equals(b)) {
return 1D;
} else {
return correlation;
}
}
What bothers me is adding this logic to a getter method, should I change the method name or documenting it should be considered enough?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…