You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: converter/README.md
+16-8Lines changed: 16 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -9,24 +9,28 @@ tags:
9
9
---
10
10
11
11
## Intent
12
-
The purpose of the Converter Pattern is to provide a generic, common way of bidirectional
12
+
13
+
The purpose of the Converter pattern is to provide a generic, common way of bidirectional
13
14
conversion between corresponding types, allowing a clean implementation in which the types do not
14
-
need to be aware of each other. Moreover, the Converter Pattern introduces bidirectional collection
15
+
need to be aware of each other. Moreover, the Converter pattern introduces bidirectional collection
15
16
mapping, reducing a boilerplate code to minimum.
16
17
17
18
## Explanation
18
19
19
20
Real world example
20
21
21
-
> In real world applications it is often the case that database layer consists of entities that need to be mapped into DTOs for use on the business logic layer. Similar mapping is done for potentially huge amount of classes and we need a generic way to achieve this.
22
+
> In real world applications it is often the case that database layer consists of entities that need
23
+
> to be mapped into DTOs for use on the business logic layer. Similar mapping is done for
24
+
> potentially huge amount of classes and we need a generic way to achieve this.
22
25
23
26
In plain words
24
27
25
28
> Converter pattern makes it easy to map instances of one class into instances of another class.
26
29
27
30
**Programmatic Example**
28
31
29
-
We need a generic solution for the mapping problem. To achieve this, let's introduce a generic converter.
32
+
We need a generic solution for the mapping problem. To achieve this, let's introduce a generic
33
+
converter.
30
34
31
35
```java
32
36
publicclassConverter<T, U> {
@@ -77,7 +81,7 @@ public class UserConverter extends Converter<UserDto, User> {
77
81
}
78
82
```
79
83
80
-
Now mapping between User and UserDto becomes trivial.
84
+
Now mapping between `User` and `UserDto` becomes trivial.
81
85
82
86
```java
83
87
var userConverter =newUserConverter();
@@ -86,14 +90,18 @@ var user = userConverter.convertFromDto(dtoUser);
0 commit comments