Exploring Design Patterns in the JDK

Design Patterns are software design solutions that can be applied in our daily software development to help us develop code that is flexible, resilient to change and easily understood (when you are familiar with the pattern). The JDK APIs employ patterns in several areas. So even if you aren’t familiar with patterns if you’ve programmed in Java, you’ve been developing against APIs that have been built using patterns.

One of the JDK APIs that has always thrown me for a spin is java.io with its gamut of InputStream and OutputStream classes. I never had a full grasp of how the API was meant to be used until recently. I knew just enough to get what I needed to get done without going down the rabbit hole. While reading the excellent Head First Design Patterns book, the chapter on the Decorator Pattern demonstrated how the java.io API is built on the Decorator Pattern. Once I made this connection, the complexity of java.io disappeared. This also explained why the API seems like a mess to begin with. If you’ve used the decorator pattern you can quite easily discern that the apparent API complexity is one downside to this pattern.

I intend to start a blog series on exploring the patterns that exist in the JDK APIs. The JDK APIs are fertile terrritory to see patterns as applied in the real world instead of the text book examples found in many design pattern books. The goal is two-fold. One to understand the APIs from our understanding of the patterns. And two to understand the patterns from our understanding of the APIs. Hopefully with this double-ended approach our understanding and appreciation of both the pattern and the API will be enhanced.

Please use the comments to point out any patterns/APIs that you would like to see in this series. My first post will be on the java.io APIs.

One comment

Comments are closed.