It's not just a matter of taste. If there isn't any extra logic in the setXXX()
methods, the convention is to assign the attributes directly in the constructor:
this.foreName = foreName;
this.surName = surName;
... And so on. But if there is extra logic in the setXXX()
methods, then you should use them as required. Say, a call to logging logic or similar:
public void setForeName(String pForeName) {
log.info("setting new foreName value: " + pForeName);
this.foreName = pForeName;
}
See how the last line in setForeName()
is the same as performing a direct assignment? Also notice that calling a setXXX()
might have a very, very small cost in performance (most likely optimized away by the JIT compiler). Under normal circumstances you should optimize for readability and clarity above all, and IMHO using a direct assignment here is the preferred option.