mercredi 7 janvier 2015

What is the best practice to set parameters to object and avoid spread code?

I'm working in a project that have some entities, and to set the entities attributes, we have a lot of code like this:



public void recordLogFile(int fileSize, int fileHeight, Long idFile) {

try {

LogFileEntity logEntity = new LogFileEntity();
logEntity.setFileSize();
logEntity.setFileHeight();
logEntity.setFile(FileEntity.find(idFile));
logEntity.setStatus(LogStatus.SUCESS);
logEntity.setType(LogType.NORMAL);
logEntity.persist();

} catch (Exception e) {
some log code
}

}


There's a lot of classes that needs to persist the log file entity but in some cases we have differente values on attributes.. For example LogStatus.FAIL LogType.OLD, and we have repetead piece of code only changing the value...


What is the best approach to make this better??


Thanks !!!


Aucun commentaire:

Enregistrer un commentaire