What is the difference between the Data Mapper, Table Data Gateway (Gateway), Data Access Object (DAO) and Repository patterns?

Your example terms; DataMapper, DAO, DataTableGateway and Repository, all have a similar purpose (when I use one, I expect to get back a Customer object), but different intent/meaning and resulting implementation. A Repository “acts like a collection, except with more elaborate querying capability” [Evans, Domain Driven Design] and may be considered as an “objects in … Read more

Who should handle the conditions in complex queries, the data mapper or the service layer?

The data mapper pattern only tells you, what it is supposed to do, not how it should be implemented. Therefore all the answers in this topic should be treated as subjective, because they reflect each authors personal preferences. I usually try to keep mapper’s interface as simple as possible: fetch(), retrieves data in the domain … Read more