本文介绍了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.

人们改变的主要原因是因为 域对象。当使用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.

另一方面,在对象和数据库之间移动数据,同时保持它们彼此独立和映射器本身。虽然更难实现,但它允许在应用程序中更灵活的设计。您的域对象不再必须匹配数据库结构。 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更现代的趋势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 00:30