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