During code review we are discussing on code comment part. One of our team member suggest to put default comment on all setter/getter methods. Are they really useful if yes then what are the use of putting default comments.
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the billType
*/
public BillType getBillType() {
return billType;
}
/**
* @param billType the billType to set
*/
public void setBillType(BillType billType) {
this.billType = billType;
}
/**
* @return the lateCharge
*/
public Float getLateCharge() {
return lateCharge;
}
/**
* @param lateCharge the lateCharge to set
*/
public void setLateCharge(Float lateCharge) {
this.lateCharge = lateCharge;
}
/**
* @return the lateChargeType
*/
public LateChargesType getLateChargeType() {
return lateChargeType;
}
/**
* @param lateChargeType the lateChargeType to set
*/
public void setLateChargeType(LateChargesType lateChargeType) {
this.lateChargeType = lateChargeType;
}
/**
* @return the billDay
*/
public String getBillDay() {
return billDay;
}
Thanks :)
There is no right or wrong answer, this is a matter of opinion.
Personally though, I think comments on a getter or setter are redundant, as it's usually pretty obvious what such a method does. Unless it has some sort of side effects or special case, do you think a comment really adds any information to a getter/setter method?
In this example, setBuildType
sets the build type of the object, this is obvious from the method name and from a quick scan of the method. Do you really need to take up an extra three lines of vertical screen space explaining it?
Let's say the setBuildType
method had side effects, and when you set the build type it changes other variables in your object, or calls into other methods based on the build type you set, then perhaps a comment explaining these side effects would be useful for users of the method.