Today, when I deal with code. I meet with this problem. For example:
public void method(Entity entity){
if(entity.getA() != 5){
entity.setA(2);
}
if(entity.getB() != 5){
entity.setB(2);
}
....// next is other field like C,D,E...
}
My question is that there are so many fields in our object. If I do the same logic in different fields I will input so much code. Is there any idea to deal with this problem? My idea is use Reflection.
My work is to do data-clean. Like the example above if the field is not 5, I will change it to 2. Also I will do this operation to every field.
Sorry my English is not so good, if you can't understand what I say,you could leave a message. Thank you!