What are design patterns?
Design patterns are solutions to known problems. The pattern represents an abstracted solution to a commonly experienced problem. As the solution is abstracted it is language agnostic.
A non-programmatic analogy is to think about how to solve the problem of getting wet when it rains. A common problem in rainy countries like the UK.
There are several solutions: wear a hat, stay at home and wait for the rain to stop, run fast so as to avoid most of the rain. These are not the best solutions, they go some way to reduce getting wet or avoiding the wetness altogether. But none are really that satisfactory.
What we need is a way to leave the house, not get wet and to do so with minimal effort and cost. We want some kind of cover over our head that deflects the rain. This is the abstraction of the solution.
Luckily we have solved this problem with the invention of the umbrella.
The umbrella design pattern
It prevents 99% of the rain while allowing us to leave the house. The umbrella is the implementation of the abstraction and it can be implemented in many ways, colors, shapes, and sizes. We choose the way that it is implemented and it does not matter as long as it follows the ‘pattern’ of an umbrella it will always keep your head dry.
Implementations of the Umbrella design pattern
This is, in essence, the idea of a design pattern. A reusable abstraction of a solution to a common problem.
How did they come about?
Design pattern has been around for many years and the concept of reusable solutions has been around for millenniums and have been used extensively in architecture. However, the most important influence in the design pattern was the publication of the book Design Patterns: Elements of Reusable Object-Oriented Software¹ in 1994. The authors have become very well known and respected in the Java community and are known as the gang of four.
The definition given to design patterns by the gang of four is that design patterns are “descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.”.
Design Patterns: Elements of Reusable Object-Oriented Software is the seminal work on design patterns and is still in publication today. The fact that it is still relevant stands as testimony to the reusability of design patterns. However, this book was written before the existence of Enterprise Java and therefore does not show how to implement the design patterns in Java EE. This way myself (Alex Theedom) and Murat Yener collaborated on a book that explains how to implement many of the Gang of Four design patterns in Java EE. We show how to implement these patterns using semantics only available in Java EE. Our book is titled Professional Java EE Design Patterns² and is available from Amazon.com. Click the book image below.
1. Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley, 1994): Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides.
2. Professional Java EE Design Patterns (Wiley, 2015): Murat Yener and Alex Theedom