Pattern Template
What template should I use for documenting a pattern?
My Basic Template
This is the template I presented in my talk "How to Write a Pattern" at WebSphere Technical Exchange 2006. It's not "mine" in that I've worked with lots of people who have helped develop it over the years, starting with Christopher Alexander himself (whom I've never worked with directly). But for anyone who disagrees with this template, fine, this is in my opinion a good template and the one I tend to use.
The template:
- Name
- Intention revealing noun phrase
- Context
- Reader's activity that leads to problem
- Problem
- Difficulty reader needs to solve
- Forces
- What makes the problem difficult to solve?
- Discusses possible solutions that ultimately don't work
- Solution
- How to solve the problem and balance the forces
- Not a bad solution - that's an antipattern
- A good solution - that's a pattern
- Results
- Details about the Solution
- Reader's situation now that problem has been solved
- Examples
- Show the pattern in action
- Show known uses of the pattern
Other Templates
There are lots of opinions about pattern templates, and therefore lots of templates. Here are some options:
- The template in Enterprise Integration Patterns is shown in the Introduction
in the "Pattern Form" section. Notice that it's very similar to the one I presented because I wrote the presentation and am a co-author of the book. The book's template has more sections; for simplicity, I only list the required sections in my presentation. Note too that in the book, we don't label the sections in a pattern (except for the Examples).
- Core J2EE Patterns template
– This is fairly similar to the template I use.
- Design Patterns (GoF) template
– I've used this quite successfully for patterns on how to design good OO code. But this template is very different from the problem-solution pair I prefer, and not a good general purpose template (MHO).
- Ward's Wiki has a couple of options:
Examples
Examples are a little hard to come by because most of them have copyrights. One place that has a lot of good examples of patterns using the template I like plus a good example of an overall pattern language is--if I may say so myself--Enterprise Integration Patterns. Seriously, it's a good example of what the whole pattern and pattern language thing is all about.