What Is a Data Mapper?
A data mapper is a separate layer responsible for transferring data between in-memory domain objects and the database without either side knowing about the other. Domain classes stay free of any storage code, and the mapper handles loading, saving, and mapping fields. Many ORMs implement this pattern under the hood.
Why it matters
Keeping persistence out of domain objects lets the model focus on behavior and rules. It also lets the database schema and the object model evolve somewhat independently.
Related guides
What Is the Active Record Pattern?The active record pattern gives each object both its data and the methods to load, save, and delete itself, c…
What Is the Repository Pattern?The repository pattern provides a collection-like interface for accessing domain objects, hiding the details…
What Is a Unit of Work?A unit of work tracks changes to objects during a business operation and commits them together as a single co…