Home » Php » php – Data Mapper vs Data access object. Difference. Which one is the better one?

php – Data Mapper vs Data access object. Difference. Which one is the better one?

Posted by: admin July 12, 2020 Leave a comment

Questions:

Possible Duplicate:
ORM/DAO/DataMapper/ActiveRecord/TableGateway differences?

Can someone help me to understand difference between data mapper and data access object patterns? I already know about data mapper pattern from zandstra’s book. But when i searched for data access object, i found out that there are very similar, or even the same patterns. Also i want to know which one i should use when writing my own framework(i’m trying to implement my own mvc php framework just to learn how modern frameworks work).

How to&Answers:

Data mapper saves the data from (and restores to) domain object directly, while data access object would be used as intermediary for exchange of information between domain object and storage abstraction.

<update>
The main difference between two approaches is that data mapper temporary takes control of the domain object, while data access object either receives data indirectly (through some higher level abstraction, like Service) or is controlled (and in some implementations, even instantiated) by domain object.</update>

Neither of patterns is remotely related to active record (anti)pattern, which combines domain logic and storage abstraction in single instance, thus breaking SRP.

And none of mentioned patterns are tied to ORMs. Some ORMs try to use the above mentioned pattern for implementation, but they usually do a quite bad job at that.

Most of, what you call, “modern frameworks” use active record pattern and call the instances of it “models”, which extreme simplification of concept, perpetuated by Rails.