Data Mapper是比Active Record更现代的趋势 [英] Is Data Mapper a more modern trend than Active Record

查看:314
本文介绍了Data Mapper是比Active Record更现代的趋势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了几个ORM,它们最近宣布计划将其实现从Active Record移动到Data Mapper。我对这个问题的了解非常有限。所以一个问题,对于那些谁知道更好,是Data Mapper比Active Record更新?当活动记录运动开始时它在什么地方?

I've come across a couple of ORMs that recently announced they are planning to move their implementation from Active Record to Data Mapper. My knowledge of this subject is very limited. So a question for those who know better, is Data Mapper newer than Active Record? Was it around when the Active Record movement started? How do the two relate together?

最后,因为我不是一个数据库人,对这个问题知之甚少,我应该遵循移动到Data Mapper实现的ORM

Lastly since I'm not a database person and know little about this subject, should I follow an ORM that's moving to the Data Mapper implementation, as in what's in it for me as someone writing software (not a data person)?

推荐答案

DataMapper不是更现代的或更新,但更适合一个ORM。

The DataMapper is not more modern or newer, but just more suited for an ORM.

人们改变的主要原因是因为 ActiveRecord 不会创造良好的ORM 。 AR 在数据库表或视图中封装一行,封装数据库访问,并在该数据上添加域逻辑。因此,根据定义,AR是数据库记录的1:1表示,这使得它特别适合于简单的CRUD。

The main reason people change is because ActiveRecord does not make for a good ORM. An AR wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data. So by definition, an AR is a 1:1 representation of a database record, which makes it particular suited for simple CRUD.

有些人添加了相关数据的抓取AR,这使得人们相信AR是一个ORM。不是这样。 ORM的要点是处理数据库结构和您的数据库结构之间的对象关系阻抗不匹配域对象。当使用AR时,您不会有此阻抗不匹配,因为您的AR表示数据库行,而不是正确的OO设计。您正在将数据库布局绑定到对象。一些对象关系行为模式仍然可以应用(例如延迟加载)。

Some people added fetching of related data to their AR, which made people believe AR is an ORM. It is not. The point of an ORM is to tackle the object relational impedance mismatch between your database structure and your domain objects. When using AR, you dont have this impedance mismatch because your AR represents a database row and not a proper OO design. You are tieing your db layout to your objects. Some of the object-relational behavioral patterns can still be applied though (for instance lazy loading).

AR经常被批评的另一个原因是它混合了两个问题:business逻辑和db访问逻辑。这导致不希望的耦合,并且可能导致在较大应用中较小的可维护性和灵活性。在两个层之间没有隔离。耦合总是导致灵活性较低。

Another reason why AR is often criticised is because it intermingles two concerns: business logic and db access logic. This leads to unwanted coupling and can result in less maintainability and flexibility in larger applications. There is no isolation between the two layers. Coupling always leads to less flexibility.

DataMapper 另一方面,在对象和数据库之间移动数据,同时保持它们彼此独立和映射器本身。虽然更难实现,但它允许在应用程序中更灵活的设计。您的域对象不再必须匹配数据库结构。 DAL和域层解耦。

A DataMapper on the other hand moves data between objects and a database while keeping them independent of each other and the mapper itself. While more difficult to implement, it allows for much more flexible design in your application. Your domain objects no longer have to match the db structure. DAL and Domain layer are decoupled.

这篇关于Data Mapper是比Active Record更现代的趋势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆