views:

106

answers:

2

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?

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)?

+2  A: 

my 2 cents:

DataMapper is newer than ActiveRecord. I like DataMapper's syntax better; it is more explicit and less "magical". I could go through more reasons, but they are listed here: http://datamapper.org/why

ActiveRecord has a lot more documentation.

phaedryx
AR and DataMapper are language agnostic design patterns. You seem to be refering to concrete implementations in the RoR world, which is not what the OP asked for.
Gordon
The question seems to have changed since I answered it :(
phaedryx
@phaedryx, The question never changed. Only the tags were edited.
jblue
+7  A: 

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

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.

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).

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.

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.

Gordon