well i've a good question about verification of relationships.
Follows below the three classes to suppose the question:
public class Son {
private Integer idSon;
private String name;
private Father father;
}
public class Father {
private Integer idFather;
private String name;
private GrandFather grandFather;
}
public class GrandFather {
private Integer idGrandFather;
private String name;
}
Following these principies, let's suppose that we've to do relationships verifications, instead every time we do something like this "in differents parts of our code":
Son son = new SonBusiness().getById(idSon); //Get a Son from database
if(son.getFather == null){
throw new Throwable("Father's Son does not exist");
}
wouldn't be better create some method like:
public void verifySonsDatas(Son son, Bollean verifyFather, Boolean verifyGrandFather) throws Throwable{
if(son == null){
throw new Throwable("Son does not exist");
}
if(verifyFather){
if(son.getFather == null){
throw new Throwable("Father's Son does not exist");
}
}
and so on for any son's ralationships..
Somebody else agree that with this approach we avoid many redundant codes and we can concentrate the verification inside an unique method...?
If we think about 10 relations, imagine writting if(object == null) it does not appear be a good thing for me.
Thanks!