I was looking at DataMapper, which appeared at first glance to use the ActiveRecord ORM pattern. Other people said that it uses the DataMapper and/or the Domain Object pattern.
What is the difference between those patterns?
The main difference between the two patterns is this:
In the ActiveRecord you have one domain object that both knows all the business logic and how to save/update itself in the database, user.getLinkToProfile()
and User::find(1)
, User::save(user)
In the DataMapper pattern you have one domain object that holds all the business logic, for exmaple user.getLinkToProfile()
(or something similar) but knows nothing about the database in question, in addition to this you have a mapper-object that is responsible for saving, updating, selecting, etc. user objects from the database which would have UserMapper::find(1)
, UserMapper.save(user)
DataMapper is potentially more complex then ActiveRecord but it's a lot easier to develop your domain model and database asynchronous than with ActiveRecord.