I have got a DAO e.g.
public class Foo {
private final int ID;
private String text;
private String title;
public void refresh() {
Foo refreshedFoo=Database.getInstance().getFooById(ID);
// *** Problem here ***
}
// ... Getters and setters for all fields
}
Sometimes I need to update all fields of a DAO (refresh it from DB). So how to set all propertys of this to the corresponding values of refreshedFoo, without writing an assignment for each property?
Unless you use some library (probably based on reflection) to do the same thing there is no other way to assign each property other than, well, assigning each property.
The alternative is to use the new instance
refreshedFooand throw away the old one, if that is possible for your application. Maybe you can have a ProxyFoo that just contains a pointer to a Foo that can be switched on refresh?