I have two class:
InputForm.java
public class InputForm {
private String brandCode;
private String caution;
public String getBrandCode() {
return brandCode;
}
public void setBrandCode(String brandCode) {
this.brandCode = brandCode;
}
public String getCaution() {
return caution;
}
public void setCaution(String caution) {
this.caution = caution;
}
}
CopyForm.java
public class CopyForm {
private boolean brandCodeChecked;
private boolean cautionChecked;
public boolean isBrandCodeChecked() {
return brandCodeChecked;
}
public void setBrandCodeChecked(boolean brandCodeChecked) {
this.brandCodeChecked = brandCodeChecked;
}
public boolean isCautionChecked() {
return cautionChecked;
}
public void setCautionChecked(boolean cautionChecked) {
this.cautionChecked = cautionChecked;
}
}
I want to copy values from an InputForm to another if its corresponding property in CopyForm is true. This is what I do:
if(copyForm.isBrandCodeChecked()) {
inputForm.setBrandCode(otherInputForm.getBrandCode());
}
if(copyForm.isCautionChecked()) {
inputForm.setCaution(otherInputForm.getCaution());
}
The problem is I have many many properties. Writing many if statements seems ugly and bad programming practice. How to solve it? (I know reflection is not a good choice so I don't think about it)