Skip to content

Commit 13cb2e8

Browse files
authored
docs: Data mapper1762 (iluwatar#2165)
* update README.md * update README.md
1 parent 4cd8149 commit 13cb2e8

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

data-mapper/README.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,53 @@ title: Data Mapper
33
category: Architectural
44
language: en
55
tags:
6-
- Decoupling
6+
- Decoupling
77
---
88

99
## Intent
1010
A layer of mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself
1111

12+
This layer consists of one or more mappers (or data access objects) that perform data transfer. The scope of mapper implementations varies.
13+
A generic mapper will handle many different domain entity types, a dedicated mapper will handle one or a few.
14+
15+
## Explanation
16+
17+
Real-world example
18+
19+
> When accessing web resources through a browser, there is generally no need to interact with the server directly;
20+
> the browser and the proxy server will complete the data acquisition operation, and the three will remain independent.
21+
22+
In plain words
23+
24+
> The data mapper will help complete the bi-directional transfer of persistence layer and in-memory data.
25+
26+
Wikipedia says
27+
28+
> A Data Mapper is a Data Access Layer that performs bidirectional transfer of data between a
29+
> persistent data store (often a relational database) and an in-memory data representation (the domain layer).
30+
31+
Programmatic example
32+
1233
## Class diagram
1334
![alt text](./etc/data-mapper.png "Data Mapper")
1435

1536
## Applicability
1637
Use the Data Mapper in any of the following situations
1738

18-
* when you want to decouple data objects from DB access layer
39+
* when you want to decouple data objects from DB access layer
1940
* when you want to write multiple data retrieval/persistence implementations
2041

21-
## Credits
42+
## Known uses
43+
* [SqlSession.getMapper()](https://mybatis.org/mybatis-3/java-api.html)
44+
45+
## Consequences
2246

23-
* [Data Mapper](http://richard.jp.leguen.ca/tutoring/soen343-f2010/tutorials/implementing-data-mapper/)
47+
> Neatly mapped persistence layer data
48+
> Data model follows the single function principle
49+
50+
## Related patterns
51+
* [Active Record Pattern](https://en.wikipedia.org/wiki/Active_record_pattern)
52+
* [Object–relational Mapping](https://en.wikipedia.org/wiki/Object%E2%80%93relational_mapping)
53+
54+
## Credits
55+
* [Data Mapper](http://richard.jp.leguen.ca/tutoring/soen343-f2010/tutorials/implementing-data-mapper/)

0 commit comments

Comments
 (0)