diff --git a/tolerant-reader/README.md b/tolerant-reader/README.md index 922de90deb0fc45ff88b0c2014cef18e47aa95f3..30517b7b886a5eb6b1da2868106335e436e1ec69 100644 --- a/tolerant-reader/README.md +++ b/tolerant-reader/README.md @@ -9,14 +9,18 @@ tags: --- ## Intent -Tolerant Reader is an integration pattern that helps creating robust communication systems. The idea is to be as -tolerant as possible when reading data from another service. This way, when the communication schema changes, the -readers must not break. + +Tolerant Reader is an integration pattern that helps creating robust communication systems. The idea +is to be as tolerant as possible when reading data from another service. This way, when the +communication schema changes, the readers must not break. ## Explanation + Real world example -> 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. +> 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. In plain words @@ -24,11 +28,11 @@ In plain words [Robustness Principle](https://java-design-patterns.com/principles/#robustness-principle) says -> Be conservative in what you do, be liberal in what you accept from others +> Be conservative in what you do, be liberal in what you accept from others. **Programmatic Example** -Here's the versioned rainbowfish. Notice how the second version introduces additional properties. +Here's the versioned `RainbowFish`. Notice how the second version introduces additional properties. ```java public class RainbowFish implements Serializable { @@ -104,7 +108,8 @@ public class RainbowFishV2 extends RainbowFish { } ``` -Next we introduce the rainbowfish serializer. This is the class that implements the Tolerant Reader pattern. +Next we introduce the `RainbowFishSerializer`. This is the class that implements the Tolerant Reader +pattern. ```java public final class RainbowFishSerializer { @@ -185,18 +190,23 @@ And finally here's the full example in action. LOGGER.info("deserializedFishV2 name={} age={} length={} weight={}", deserializedFishV2.getName(), deserializedFishV2.getAge(), deserializedFishV2.getLengthMeters(), deserializedFishV2.getWeightTons()); - - // fishV1 name=Zed age=10 length=11 weight=12 - // deserializedFishV1 name=Zed age=10 length=11 weight=12 - // fishV2 name=Scar age=5 length=12 weight=15 sleeping=true hungry=true angry=true - // deserializedFishV2 name=Scar age=5 length=12 weight=15 ``` +Program output: + +``` +fishV1 name=Zed age=10 length=11 weight=12 +deserializedFishV1 name=Zed age=10 length=11 weight=12 +fishV2 name=Scar age=5 length=12 weight=15 sleeping=true hungry=true angry=true +deserializedFishV2 name=Scar age=5 length=12 weight=15 +``` ## Class diagram -![alt text](./etc/tolerant-reader.png "Tolerant Reader") + +![alt text](./etc/tolerant_reader_urm.png "Tolerant Reader") ## Applicability + Use the Tolerant Reader pattern when * The communication schema can evolve and change and yet the receiving side should not break diff --git a/tolerant-reader/etc/tolerant-reader.png b/tolerant-reader/etc/tolerant-reader.png deleted file mode 100644 index 45f0302a2c7bd80c975f20ed67eb700d0224e368..0000000000000000000000000000000000000000 Binary files a/tolerant-reader/etc/tolerant-reader.png and /dev/null differ diff --git a/tolerant-reader/etc/tolerant-reader.ucls b/tolerant-reader/etc/tolerant-reader.ucls deleted file mode 100644 index 92e069f8e6e1623ccbfbac41d078380976a5315f..0000000000000000000000000000000000000000 --- a/tolerant-reader/etc/tolerant-reader.ucls +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tolerant-reader/etc/tolerant_reader_urm.png b/tolerant-reader/etc/tolerant_reader_urm.png new file mode 100644 index 0000000000000000000000000000000000000000..9f5499172ee92da0597eb18b04d99fd0d5b71abe Binary files /dev/null and b/tolerant-reader/etc/tolerant_reader_urm.png differ