Saturday, 10 August 2013

Data Mapper Design Pattern

Master Software Architecture & Design Patterns!

Subscribe to Ram N Java for beginner-friendly, practical software engineering guides!

🔔 Subscribe to Our Channel

What is the Data Mapper Pattern?

The Data Mapper design pattern belongs to the data source architectural patterns family within enterprise application architecture. In simple terms, a Data Mapper is a layer of mappers that moves data between objects and a database while keeping them completely independent of each other and the mapper itself.

Unlike other database patterns where domain objects manage their own persistence logic or match table schemas directly, a Data Mapper serves as an isolated layer of software that separates in-memory domain models from relational database structures.

Real-World Example: Person Object & PersonMapper

Consider an enterprise application managing user records with a database table named Person (containing columns like Last Name, First Name, and Number of Dependents):

  • In-Memory Domain Object: The Person class models pure business entities (such as Joe or Gopi) without holding any database connection or SQL query code.
  • The PersonMapper Layer: Sits directly between the Person object and the database.
    • Saving Data: Reads values from the Person object, formulates SQL INSERT statements, and executes them against the database.
    • Updating Data: Formulates and executes SQL UPDATE queries using domain object data.
    • Retrieving Data: Queries the database table and populates/constructs a fresh in-memory Person object.

Key Advantages

  • Complete Separation of Concerns: In-memory domain objects don't even need to know that a database exists—they require zero SQL interface code and no knowledge of the database schema.
  • Independent Evolution: The database schema and domain business models can evolve independently without breaking each other.
  • Cleaner Unit Testing: Because domain objects are free of database persistence dependencies, they can be tested in memory quickly and effortlessly.

Click here to watch in Youtube : https://www.youtube.com/watch?v=DWiupph7ezE

Click the below Image to Enlarge
Data Mapper Design Pattern














See also:

  • All Design Patterns Links
  • 1 comment:

    1. When you start looking in the market, you will come across a vast range and variety of timber floors and in the diverse price range. Here are some of the most common and different types of timber floors available.

      Timber Flooring in Williams Landing

      ReplyDelete

    Tutorials