Sponsored Links
-->

Tuesday, June 26, 2018

Data Access Object Design Pattern - Introduction - YouTube
src: i.ytimg.com

In computer software, a data access object (DAO) is an object 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).

Although this design pattern is equally applicable to most programming languages, most types of software with persistence needs, and most types of databases, 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 "Core J2EE Patterns" for that platform).


Video Data access object



Advantages

The advantage of using data access objects is the relatively simple and rigorous separation between two important parts of an application that can but should not know anything 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. All details of storage are hidden from the rest of the application (see information hiding). Thus, possible changes to the persistence mechanism can be implemented by just modifying one DAO implementation while the rest of the application isn't affected. DAOs act as an intermediary between the application and the database. They move data back and forth between objects and database records. Unit testing the code is facilitated by substituting the DAO with a test double in the test, thereby making the tests non-dependent on the persistence layer.

In the non specific context of the Java programming language, Data Access Objects as a design concept can be implemented in a number of ways. This can range from a fairly simple interface that separates the data access parts from the application logic, to frameworks and commercial products. DAO coding paradigms can require some skill. Technologies like Java Persistence API and Enterprise JavaBeans come built into application servers and can be used in applications that use a JavaEE application server. Commercial products like TopLink are available based on object-relational mapping (ORM). Popular open source ORM software include Doctrine, Hibernate, iBATIS and JPA implementations such as Apache OpenJPA.


Maps Data access object



Disadvantages

Potential disadvantages of using DAO include leaky abstraction, code duplication, and abstraction inversion. In particular, the abstraction of the DAO as a regular Java object can hide the high cost of each database access, and can also force developers to trigger multiple database queries to retrieve information that could otherwise be returned in a single operation with normal SQL set operations. If an application requires multiple DAOs, one might find oneself repeating essentially the same create, read, update, and delete code for each DAO. This boiler-plate code may be avoided however, by implementing a generic DAO that handles these common operations.


Data Access Object Design Pattern - Class and Sequence Diagram ...
src: i.ytimg.com


Example from real world

Imagine a situation where your successful company got a contract to develop an application for two different clients. The specification is roughly the same despite some minor differences. This plot has a twist though. Both clients use SQL databases but one decided to go for a proprietary one and the other chose an open source alternative. This implies that your application will have to have persistence layer implemented in at least two different ways. Naturally, many more implementations may be needed as new clients arise. Your best choice to solve this portability problem in Java EE would be using one of core J2EE patterns - Data Access Object. This pattern then ensures the right abstraction and encapsulation of all access to any data source.


Data Access Object Design Pattern - Implementation - YouTube
src: i.ytimg.com


Tools and frameworks

  • ODB compiler-based object-relational mapping (ORM) system for C++
  • ORMLite: Lightweight object-relational mapping (ORM) framework in Java for JDBC and Android
  • Microsoft Entity Framework
  • DBIx::Class object-relational mapping (ORM) module for Perl

JAVA EE: Data Access Object Design Pattern รข€
src: 4.bp.blogspot.com


See also

  • Create, read, update and delete (CRUD)
  • Data access layer
  • Service Data Objects

Java Tutorial 21:Data Access Object,Aspect oriented programming ...
src: i.ytimg.com


References


JAVA EE: Data Access Object Design Pattern or DAO Pattern
src: 3.bp.blogspot.com


External links

  • Java Persistence - The DAO Design Pattern
  • PHP best practices (Use Data Access Objects (DAO))
  • Data Access Object (English)

Source of article : Wikipedia