Reference: http://my.oschina.net/gao0516/blog/136103
Adorner mode: the ability to dynamically extend an object without having to change the original class file and use inheritance
Adapter mode: Transforms the interface of a class into another interface that the customer wants
Directly on the Code analysis:
PackageCom.think.cla;ImportJava.io.BufferedReader;Importjava.io.IOException;ImportJava.io.InputStreamReader; Public classEcho { Public Static voidMain (String [] args)throwsioexception{String Line; InputStreamReader input=NewInputStreamReader (system.in); System.out.println ("Enter data and push enter:"); BufferedReader Reader=NewBufferedReader (input); Line=Reader.readline (); System.out.println ("Data entered:" +Line ); } }
The Java I/O library has two symmetries, namely:
(1) Input-output symmetry: such as InputStream and OutputStream each occupy the input and output of the byte stream at the root of the two parallel hierarchical structure, while reader and writer occupy the root of the two parallel hierarchical structures of the input and output of the char stream respectively.
(2) Byte-char symmetry: InputStream and reader subclasses are responsible for the input of byte and char streams respectively; OutputStream and writer's subclasses are responsible for the output of byte and char streams, respectively.
As you can see, this class accepts a System.in object of type InputStream, fits it into a reader type, and then uses the
The BufferedReader class "decorates" it, adding the buffering function to it. In this way, you can use the Readerline () of the BufferedReader object
Method reads the input data for the entire row, and the data type is string.
Design Patterns in Java IO-adorners and Adapter modes