Inspiration from architecture
The first use of "patterns" comes from the works of an architect (who was also anthropolog), Christopher Alexander. He wrote a book, "A pattern language" (1977), where he presents a new language, based of timeless entities called patterns. Patterns describe a problem, and offer an universal solution.
This book is a list of 253 patterns intented to solve every conception problem in architecture at any scale, from the organisation of contries and cities to the design of door handles. In order to achieve that, he studied several cultures and noticed that for the same problem, only a finite set of reusable solutions was used.
In this book, each pattern is referenced by a number. For instance, "(12)" means "go to the Community of 7,000 pattern".
Software design patterns
Then, in 1995, the patterns where popularised by a book, "Design Patterns: Elements of Reusable Object-Oriented Software", published by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, often referred to as the Gang of Four (GoF).
They accomplished this review the same way as Alexander twenty years before. They looked for several development teams, and saw that for the same conception problems, the same solutions were found. They reduced it to a set of 23 patterns, who are general and reusable solutions for a common and recurrent conception problem.
The conception problems are not infinite, we all the time fall again on the same problems (some people think there is less than 100 problems in computer science). To reinvente a solution is long and expensive (and we can make a solution who doesn't work). The concept of patterns is to recognize the shape of the problem in order to apply the shape of a well known an proven solution to it.
What a pattern is not
- It is not a reusable or parametrizable componant.
- It is not an algorithm.
- It is not a framework.
It is a motif (or a structure) of conception corresponding to a common and proven way to resolve problems. You will have a little work to do in order to adapt it on your problem.
What is a pattern
The description of a pattern is very rich. There is more than a dozen of fields: name, classification, alias, motivation, applicability, structure, participants, collaborations, concequency, implementation, code example, known uses, related patterns... It is used to create a descriptive card of the pattern and a guideline for new patterns.
The different fields are grouped in 4 rubrics:
- The identification by a name explicite who identify a the pattern
- The description of the problem
- The problem's solution
- The positive and negative solution's concequencies
The name of the pattern is enough to reference it so every one will know about which pattern you are reffering. For instance, if someone says "it is a jardin à la française", everybody will know which type of garden it is, and what it approximately looks like.
The 23 originals ones are referenced at the GoF's patterns. Several organisation are possible. They are linked between them (they are rarely used alone), some are very specific, other are use more frequently.
Traditionally, they are organised in 3 families:
- Creationals: abstract the instanciation process
- Structurals: compose the objects and classes in large structures
- Behaviorals: assign responsiblities between the objects