DAO和Data Mapper有什么区别? [英] What's the difference between DAO and Data Mapper
问题描述
DAO模式和数据映射模式之间有区别吗? DAO只是数据映射器之一吗?
Is there a difference between the DAO pattern and the Data Mapper pattern? Is DAO just one of doing Data Mapper?
推荐答案
我实际上不会调用DAO模式。正如我看到的那样,DAO几乎是一个数据访问对象,它封装了访问持久数据存储的细节,一般来说与数据库无关:
I wouldn't actually call DAO a "pattern". As I see it, DAO is pretty much what it is -- a Data Access Object", which encapsulates the details of accessing a persistent data store and generally speaking has nothing to do with the database:
interface IBlogDaoService
{
Blog GetBlog(long id);
void SaveBlog(Blog blog);
}
很明显,实现可以使用任何一个DB(在这种情况下,使用数据映射器是合乎逻辑的)或简单的XML文件存储机制。
It's clear that implementations can use either DB (in which case it's quite logical to use a Data Mapper), or simple XML file storage mechanism.
另一方面,数据映射器更多的是一种模式,它定义了一个层,负责将对象的内存中图形转换为关系结构。
The Data Mapper on the other hand is more of a pattern, which defines a layer responsible for translating in-memory graphs of objects to the relational structure.
这篇关于DAO和Data Mapper有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!