So, I have a builder class like:
class Person{
private String age = "";
private String name = "";
public Person withAge(final String age)...
public Person withName(final String name)...
public Person build()...
// Now my question is due to this function
public Person copyWithSomeChange(){
Person person = new Person;
person.
withAge(this.age+1).
withName(this.name).
build();
}
}
So, above class has a method copyWithSomeChange() which uses an existing Person object to create a new one.
Now I want to ensure if someone adds a new field to Person class, like SSN, then they doesn't forget to add that field to copyWithSomeChange() as well. I have created a unit test using reflection and did some hacks around that, but it doesn't seem quite right.
Am I taking a complete wrong approach here, I see this to be a good thing to do but how to do it the right way?
Aucun commentaire:
Enregistrer un commentaire