Data Mapper vs Data access object. Difference. Which one is the better one? [duplicate] Data Mapper vs Data access object. Difference. Which one is the better one? [duplicate] php php

Data Mapper vs Data access object. Difference. Which one is the better one? [duplicate]


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.