浏览 5459 次
锁定老帖子 主题:关于DAO模式得问题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2004-04-02
A typical DAO implementation has the following components: A DAO factory class A DAO interface A concrete class that implements the DAO interface Data transfer objects (sometimes called value objects) 这是我在网上看得资料,因为还没有对此模式有个系统和完全得了解,所以这里想问一下: 1, DAO factory class 解释一下,作用是什么,请举个简单得例子 2,我看到有些人得部分例子里面都有DAO interface ,里面大概就是一些关于读写改删得操作定义,然后A concrete class that implements the DAO interface,我就在想:这个INTERFACE在这里是不是起一个解偶得作用,以后改变底层数据层得时候不用对业务层进行大得修改???那个具体实现的DAO在整个模式中起什么作用啊?怎么感觉和上面的FACTORY重复了??请最好举例说明这个DAO类的作用。 3,Data transfer objects解释一下。是谁生产的?DAO还是FACTORY? 我知道这个问题在论坛里面讨论过,不过请大家还是本着“致富以后不忘扶贫”的精神介绍一下,谢谢。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2004-04-02
DAO factory is needed when the application use multi databases, the business logic needn't know the dao implement which database, it just care how communicate with the dao, in this case, we need dao interface and dao factory, for example, the applicate need access both oracle and mysql, here is the dao interface:
public interface DAO { public void op1();; public void op2();; ...... } and the OracleDAO and MySQL DAO implement that interface: public class OracleDAO implements DAO { public void op1(); { ...... } public void op2(); { ...... } } public class MySQLDAO implements DAO { public void op1(); { ...... } public void op2(); { ...... } } and we have a DAO factory to decide get which real DAO public class DAOFactory { public static DAO getDAO(); { return new MySQLDAO();; } } in the business logic: ...... DAO dao = DAOFactory.getDAO();; dao.op1();; dao.op2();; ...... so in the business, it doesn't the program use which dao, it just know I have a dao can do these jobs. that's the point. |
|
返回顶楼 | |
发表时间:2004-04-02
Sorry for typed in English, I only have linux on my hand now.
|
|
返回顶楼 | |
发表时间:2004-04-02
That does not matter! Thanks for your reply!!
waiting for more explanation |
|
返回顶楼 | |
发表时间:2004-04-02
chengld Hamlet:
那么Data transfer objects 做什么角色啊?上面你的解释中你好像没有提到这个啊 |
|
返回顶楼 | |
发表时间:2004-04-02
am i not clear enough? ok, the following link is for your reference.
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html |
|
返回顶楼 | |
发表时间:2004-04-04
楼上给的连接我看过了,发现一点不同,还请大家说说:
你的FACTORY我看了,意思大概是一个FACTORY可以生产针对不同数据库的DAO来。 但是蓝皮书里面写的,意思是一个FACOTORY生产针对于一种数据库的DAO,不同的DAO实现的接口不一样。比如有三种数据库,那么就需要三种FACTORY,用一个虚拟工厂来得到不同的工厂。 请问到底应该怎么办 |
|
返回顶楼 | |
发表时间:2004-04-04
usually an application use many DAOs, like UserDAO, OrderDAO, ProductDAO, etc., in such case, you can use abstract factory to get a concrete factory, and let that concrete factory create those DAOs.
|
|
返回顶楼 | |
发表时间:2004-04-05
I got it!!
|
|
返回顶楼 | |