javarevisited

javarevisited


Data Access Object (DAO) design pattern in Java - Tutorial Example

Posted: 01 Jan 2013 04:27 AM PST

Data Access Object or DAO design pattern is a popular design pattern to implement persistence layer of Java application. DAO pattern is based on abstraction and encapsulation design principles and shields rest of application from any change on persistence layer e.g. change of database from Oracle to MySQL, change of persistence technology e.g. from File System to Database. For example if you are authenticating user using relational database and later your company wants to use LDAP to perform authentication. If you are using DAO design pattern to access database, it would be relatively safe as you only need to make change on Data Access Layer. DAO design pattern also keeps coupling low between different parts of application. By using DAO design pattern your View Layer is completely independent to DAO layer and only Service layer has dependency on it which is also abstracted by using DAO interface. You can further use Generics to template your DAO layer. If you are using Spring than you can leverage JdbcTemplate for performing JDBC calls which saves lot of boiler plate coding. Using DAO pattern to access database is one of the JDBC best practices to follow.
Read more »


Post a Comment