A data access object (DAO) is an object that
provides an abstract interface to some type of database or persistence mechanism, providing
some specific operations without exposing details of the database. It provides
a mapping from application calls to the persistence layer. This isolation separates the concerns of what data accesses the application
needs, in terms of domain-specific objects and data types (the public interface
of the DAO), and how these needs can be satisfied with a specific DBMS, database schema, etc. (the
implementation of the DAO).
This design pattern is equally applicable to most
programming languages, most types of software with persistence needs and most
types of databases, but it is traditionally associated with Java EE applications
and with relational databases accessed via the JDBC API because of its origin
in Sun Microsystems' best practice guidelines[1] ("Core J2EE Patterns") for
that platform.
The
advantage of using data access objects is the relatively simple and rigorous
separation between two important parts of an application that can and should
know almost nothing of each other, and which can be expected to evolve
frequently and independently. Changing business logic can rely on the same DAO
interface, while changes to persistence logic do not affect DAO clients as long
as the interface remains correctly implemented.
§ Can
be used in a large percentage of applications - anywhere data storage is
required.
§ Hide
all details of data storage from the rest of the application.
§ Act
as an intermediary between the application and the database. They move data
back and forth between objects and database records.
§ Allow
ripple effects from possible changes to the persistence mechanism to be
confined to a specific area
§ Appication
is independent of the data access techniques and database dependency.
§ Offers
loose coupling with the other layers of application
§ Allows
to unit test the service layer using mock objects without connecting to
database
No comments:
Post a Comment