简体   繁体   中英

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.

装饰器 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.

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.

在此处输入图像描述

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM