Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decorator pattern java.io.reader

For a school report I have to explain how the java.io.Reader package implements the Decorator pattern. I have seen multiple explanations for the java.io package (here for example) but not for the java.io.Reader package (if that's even any different). Here is what I have now, I know this design doesn't show it correctly, but I am not sure how the java.io.Reader package actually does implement it.

decorator java.io.Reader

So in this case the Reader would be the Component, the InputStreamReader the Concrete Component, the BufferedReader the Decorator and the LineNumberReader the Concrete Decorator. Again, I know this is wrong but I don't know how to correctly display it.

like image 529
Mees Kluivers Avatar asked Sep 04 '26 01:09

Mees Kluivers


1 Answers

The diagram is correct. If you have access to Intellij (or other capable tool) you can see the UML class diagram for Java types. The below snippet is one such diagram.

enter image description here

As you can see, it agrees with yours. One thing I would consider though is BufferedReader a concrete decorator since it provides additional behavior on Reader.

like image 143
ChiefTwoPencils Avatar answered Sep 05 '26 16:09

ChiefTwoPencils



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!