architect-handbook

Software Architect Handbook

View on GitHub

DAO: Data Access Object

Pattern that provides an abstract interface to some type of database or other persistence mechanism.

By mapping application calls to the persistence layer, the DAO provides some specific data operations without exposing details of the database. This isolation supports the Single Responsibility Principle.

It separates what data access the application needs, in terms of domain-specific objects and data types (the public interface of the DAO), from how these needs can be satisfied with a specific DBMS, database schema, etc (the implementation of the DAO).

Advantages

Potential Disadvantages

Hypotetical use scenario

Imagine a situtation where you receive contracts to develop an application for two different clients. The sepcifications for the application are nearly identifical for the two clients. Both clients manage data using SQL databases, but one company uses a proprietary database and the other uses an open source alternative, which implies that your application’s persistence layer will need to be implemented in two different ways. Further, as new clients arise, additional implementations may be needed. In this case, using the DAO pattern would ensure the right amount of abstraction and encapsulation required to access any of the varying backend databases.