Design Patterns

At the time I was writing the first draft of this book, I also happened to be learning about design patterns. Gradually, it became obvious that much of the AWT was written by programmers who had patterns on the brain. The java.awt.Toolkit class is a textbook example of the “abstract factory” pattern. The URL class’s openConnection() method is a factory method. The Reader and Writer classes are decorators on top of InputStream and OutputStream. The engine classes in the JCE are proxies, and I could cite many more examples. Much of the class library—including the java.io package—has been designed with design patterns, and it will all make a lot more sense if you’re familiar with the standard patterns.

The seminal text on the subject is Design Patterns, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (Addison-Wesley, 1995). The four authors are colloquially known as the “Gang of Four,” and the book is often cited informally as “GoF.” The 23 patterns covered in GoF are rapidly becoming part of the vocabulary of the object-oriented programming community. Design patterns are also beginning to be covered in many more introductory books about object-oriented programming and Java.

There are also several extremely active mailing lists and web sites devoted to design patterns. To subscribe to the list send email to with the word “subscribe” in the Subject: field. Archives of this and several related lists may be ...

Get Java I/O 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.