Active Record和DAO之间的区别?

时间:2022-04-17 13:22:45

What's the difference between a Data Access Object and Active Record? They seem to be quite the same, as both built a layer between the application and persistence layer, and abstract away direct database access using SQL queries.

数据访问对象和活动记录之间有什么区别?它们似乎完全相同,因为它们在应用程序和持久层之间构建了一个层,并使用SQL查询抽象出直接数据库访问。

2 个解决方案

#1


17  

Data Access Object (DAO) refers to an object in your data layer responsible for persisting a separate entity in your domain. Active Record is hybrid where the class containing the values of a single row from a table is also responsible for queries, updates, inserts, and deletes to that table. The Active Record design pattern means your object has a one-to-one mapping with a table in your database.

数据访问对象(DAO)是指数据层中的一个对象,负责在域中持久保存单独的实体。 Active Record是混合的,其中包含表中单行值的类也负责对该表的查询,更新,插入和删除。 Active Record设计模式意味着您的对象与数据库中的表具有一对一的映射关系。

#2


18  

A Data Access Object (DAO) is an interface dedicated to the persistence of a model/domain object to a data-source, and not just any object in the data layer. Here's a reference.

数据访问对象(DAO)是专用于将模型/域对象持久保存到数据源的接口,而不仅仅是数据层中的任何对象。这是一个参考。

The ActiveRecord pattern works in a similar fashion, but puts the persistence methods on the model object itself, while the DAO defines a discrete interface. The advantage of the DAO pattern is:

ActiveRecord模式以类似的方式工作,但将持久性方法放在模型对象本身上,而DAO定义了一个离散的接口。 DAO模式的优点是:

  • Its easy to define another style of persistence, eg moving from a Database to cloud, without changing the underlying impelementation, while the external interface remains the same, therefore not affecting other classes.

    很容易定义另一种持久性风格,例如从数据库迁移到云,而不改变底层的实例,而外部接口保持不变,因此不会影响其他类。

  • The persistence concerns are modularized away from the main model object concerns.

    持久性问题远离主要模型对象关注模块化。

The advantage of the ActiveRecord pattern is simplicity.

ActiveRecord模式的优点是简单。

#1


17  

Data Access Object (DAO) refers to an object in your data layer responsible for persisting a separate entity in your domain. Active Record is hybrid where the class containing the values of a single row from a table is also responsible for queries, updates, inserts, and deletes to that table. The Active Record design pattern means your object has a one-to-one mapping with a table in your database.

数据访问对象(DAO)是指数据层中的一个对象,负责在域中持久保存单独的实体。 Active Record是混合的,其中包含表中单行值的类也负责对该表的查询,更新,插入和删除。 Active Record设计模式意味着您的对象与数据库中的表具有一对一的映射关系。

#2


18  

A Data Access Object (DAO) is an interface dedicated to the persistence of a model/domain object to a data-source, and not just any object in the data layer. Here's a reference.

数据访问对象(DAO)是专用于将模型/域对象持久保存到数据源的接口,而不仅仅是数据层中的任何对象。这是一个参考。

The ActiveRecord pattern works in a similar fashion, but puts the persistence methods on the model object itself, while the DAO defines a discrete interface. The advantage of the DAO pattern is:

ActiveRecord模式以类似的方式工作,但将持久性方法放在模型对象本身上,而DAO定义了一个离散的接口。 DAO模式的优点是:

  • Its easy to define another style of persistence, eg moving from a Database to cloud, without changing the underlying impelementation, while the external interface remains the same, therefore not affecting other classes.

    很容易定义另一种持久性风格,例如从数据库迁移到云,而不改变底层的实例,而外部接口保持不变,因此不会影响其他类。

  • The persistence concerns are modularized away from the main model object concerns.

    持久性问题远离主要模型对象关注模块化。

The advantage of the ActiveRecord pattern is simplicity.

ActiveRecord模式的优点是简单。