Decorator (Chapter 27)

SOLUTION 27.1One answer is:
Writer out = new PrintWriter(System.out);
out = new WrapFilter(new BufferedWriter(out), 15);
((WrapFilter) out).setCenter(true);
out = new RandomCaseFilter(out);

Alternatively:

WrapFilter out =
    new WrapFilter(
        new BufferedWriter(
            new RandomCaseFilter(
                new PrintWriter(System.out))),
        15);
out.setCenter(true);

The com.oozinoz.applications package includes classes ShowFilters2 and ShowFilters3, which apply these two methods, respectively:

 package com.oozinoz.applications; import java.io.*; import com.oozinoz.io.*; public class ShowFilters3 { public static void main(String args[]) throws IOException { BufferedReader in = new BufferedReader(new FileReader(args[0])); WrapFilter out = new WrapFilter( ...

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.