Decorator pattern abstract class about IO stream

  Decoration is packaging. For example, my bicycle is stepped on by two reels. After processing and packaging a battery, it becomes a battery car, and then two wings are installed, and it becomes an electric flying bike. After going from the original bike through the layers of packaging, the function is constantly added, and it is constantly becoming something new. This is the wrapper mode. For specific examples, see the abstract class about IO streams

  For example, InputStream, look at the pictures in the link, wrap it from left to right, and finally become BufferedInputStream, if I instantiate a BufferedInputStream object like this

BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File("wlf.txt")));

  Then the bis object has both the function of the file stream and the function of the buffer stream.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324976344&siteId=291194637