For example,
PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
System.out)));
Is this the method chaining pattern?
For example,
PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
System.out)));
Is this the method chaining pattern?
Creational patterns:
Examples of GoF Design Patterns in Java's core libraries
In Java, the input/output classes are each designed to do one job well and several classes are used together to do sophisticated things.
The way in which the Java I/O classes work follows a general pattern called Decorator.
Many of the I/O classes are used to decorate objects of another I/O class by providing some "fancy packaging." We looked at decorators for strategies in Chapter 4. Here we have a different kind of decorator, but the same idea exactly.
A decorator for a Writer will itself be a writer and will provide some additional services that the object it decorates does not provide. Here, we would like to use a PrintWriter, which knows how to write most of the things known to a Java program. A print writer doesn't actually print, however.
It just knows how to format the things you give it (like ints) and pass them to the writer it decorates. We must layer up a PrintWriter onto a FileWriter to get output to a file. This is quite easily done also, though it too may throw an IOException.
PrintWriter output = new PrintWriter(new FileWriter("data.txt"));
http://www.csis.pace.edu/~bergin/KarelJava2ed/ch10/index.html