Content deleted Content added
Removed unnecessary inline list |
Added example from real world |
||
Line 24:
== Disadvantages ==
Potential disadvantages of using DAO include [[leaky abstraction]],{{Citation needed|reason=What kind of leak?|date=August 2014}} [[Duplicate code|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.<ref>See http://www.ibm.com/developerworks/java/library/j-genericdao/index.html for workarounds</ref>
== 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.
== Tools and frameworks ==
Line 42 ⟶ 45:
* [http://tutorials.jenkov.com/java-persistence/dao-design-pattern.html ''Java Persistence'' - ''The DAO Design Pattern'']
* [http://www.odi.ch/prog/design/php/guide.php PHP best practices (Use Data Access Objects (DAO))]
* [https://kore.fi.muni.cz/wiki/index.php?title=Data_Access_Object_(English) Data Access Object (English)]
{{Design Patterns Patterns}}
|