vendredi 6 mars 2015

What is the improvement of using DAO in Java SE?

My project manager wants me to use DAO/DTO objects to access and retrieve data from database. Project is written in Java SE without using any framework or ORM. His arguments is to make code more testable and to improve code design. Does it make sense?


How about initializing DAO object? Should it be initialized when the instance of class having DAO field is created:



private PersonDao personDao = new PersonDaoImpl();


or rather initialized when it is necessary?



public class A {
private PersonDao person;

public List<Person> findAll() {
person = new PersonDaoImpl();
return person.getAll();
}
}


It allows to mock this interface easily, but is it right to the DAO pattern usage convention?


Aucun commentaire:

Enregistrer un commentaire