DAO 和 Data Mapper 有什么区别

发布于 2024-07-12 13:07:51 字数 52 浏览 6 评论 0原文

DAO 模式和数据映射器模式之间有区别吗? DAO只是做Data Mapper的一种吗?

Is there a difference between the DAO pattern and the Data Mapper pattern? Is DAO just one of doing Data Mapper?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分开我的手 2024-07-19 13:07:51

我实际上不会将 DAO 称为“模式”。 在我看来,DAO 几乎就是它的本质——一个“数据访问对象”,它封装了访问持久数据存储的细节,一般来说与数据库无关:

interface IBlogDaoService
{
    Blog GetBlog(long id);
    void SaveBlog(Blog blog);
}

很明显,实现可以使用任一 DB (在这种情况下,使用数据映射器是非常合乎逻辑的,或者简单的 XML 文件存储机制

另一方面,数据映射器更多的是一种模式,它定义了一个负责将内存中的对象图转换为关系结构的层。 。

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);
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文