I'm learning about the Data Access Object pattern, which provides access to a source of data, such as a database. This answer to another question provides the following example:
interface EmployeeDAO {
List<Employee> findAll();
List<Employee> findById();
List<Employee> findByName();
boolean insertEmployee(Employee employee);
boolean updateEmployee(Employee employee);
boolean deleteEmployee(Employee employee);
}
I see similar examples in other answers and articles around the internet. What confuses me is the fact that reading from and writing to a database often take a while, in which case these examples (particularly the find...()
ones) would not be very practical as far as I can tell. That is, blocking during a find...()
call would probably not be desired behavior.
I'm thinking it could make sense to create a Listener interface (EmployeeDAO.Listener
) with methods such as void EmployeeFound(Employee employee)
, but I'm surprised I haven't seen this before in DAO examples. I wonder if I'm just not understanding Data Access Objects and/or if I'm missing a more obvious approach.
Aucun commentaire:
Enregistrer un commentaire