Skip to content

Commit 24e8fa1

Browse files
committed
Update README.md
1 parent 9017975 commit 24e8fa1

File tree

4 files changed

+23
-65
lines changed

4 files changed

+23
-65
lines changed

tolerant-reader/README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,30 @@ tags:
99
---
1010

1111
## Intent
12-
Tolerant Reader is an integration pattern that helps creating robust communication systems. The idea is to be as
13-
tolerant as possible when reading data from another service. This way, when the communication schema changes, the
14-
readers must not break.
12+
13+
Tolerant Reader is an integration pattern that helps creating robust communication systems. The idea
14+
is to be as tolerant as possible when reading data from another service. This way, when the
15+
communication schema changes, the readers must not break.
1516

1617
## Explanation
18+
1719
Real world example
1820

19-
> We are persisting rainbowfish objects to file and later on they need to be restored. What makes it problematic is that rainbowfish data structure is versioned and evolves over time. New version of rainbowfish needs to be able to restore old versions as well.
21+
> We are persisting rainbowfish objects to file and later on they need to be restored. What makes it
22+
> problematic is that rainbowfish data structure is versioned and evolves over time. New version of
23+
> rainbowfish needs to be able to restore old versions as well.
2024
2125
In plain words
2226

2327
> Tolerant Reader pattern is used to create robust communication mechanisms between services.
2428
2529
[Robustness Principle](https://java-design-patterns.com/principles/#robustness-principle) says
2630

27-
> Be conservative in what you do, be liberal in what you accept from others
31+
> Be conservative in what you do, be liberal in what you accept from others.
2832
2933
**Programmatic Example**
3034

31-
Here's the versioned rainbowfish. Notice how the second version introduces additional properties.
35+
Here's the versioned `RainbowFish`. Notice how the second version introduces additional properties.
3236

3337
```java
3438
public class RainbowFish implements Serializable {
@@ -104,7 +108,8 @@ public class RainbowFishV2 extends RainbowFish {
104108
}
105109
```
106110

107-
Next we introduce the rainbowfish serializer. This is the class that implements the Tolerant Reader pattern.
111+
Next we introduce the `RainbowFishSerializer`. This is the class that implements the Tolerant Reader
112+
pattern.
108113

109114
```java
110115
public final class RainbowFishSerializer {
@@ -185,18 +190,23 @@ And finally here's the full example in action.
185190
LOGGER.info("deserializedFishV2 name={} age={} length={} weight={}",
186191
deserializedFishV2.getName(), deserializedFishV2.getAge(),
187192
deserializedFishV2.getLengthMeters(), deserializedFishV2.getWeightTons());
188-
189-
// fishV1 name=Zed age=10 length=11 weight=12
190-
// deserializedFishV1 name=Zed age=10 length=11 weight=12
191-
// fishV2 name=Scar age=5 length=12 weight=15 sleeping=true hungry=true angry=true
192-
// deserializedFishV2 name=Scar age=5 length=12 weight=15
193193
```
194194

195+
Program output:
196+
197+
```
198+
fishV1 name=Zed age=10 length=11 weight=12
199+
deserializedFishV1 name=Zed age=10 length=11 weight=12
200+
fishV2 name=Scar age=5 length=12 weight=15 sleeping=true hungry=true angry=true
201+
deserializedFishV2 name=Scar age=5 length=12 weight=15
202+
```
195203

196204
## Class diagram
197-
![alt text](./etc/tolerant-reader.png "Tolerant Reader")
205+
206+
![alt text](./etc/tolerant_reader_urm.png "Tolerant Reader")
198207

199208
## Applicability
209+
200210
Use the Tolerant Reader pattern when
201211

202212
* The communication schema can evolve and change and yet the receiving side should not break
-20 KB
Binary file not shown.

tolerant-reader/etc/tolerant-reader.ucls

Lines changed: 0 additions & 52 deletions
This file was deleted.
45 KB
Loading

0 commit comments

Comments
 (0)