Design Patterns have flopped?
I came across this article recently “Design patterns have (mostly) flopped” from a recruitment website (if my boss is reading this, I was not looking for a new job). The crux of their argument is “Design patterns have flopped because most programmers don’t know design patterns well enough to recognise the recurring problems that they solve.” They go on to say that the vast majority of the thousands of programmers they have asked to name some of the common patterns don’t even know what design patterns are.
I’m calling BS on their argument. Their point of view is more to do with the lack of experience the programmers have as opposed to the purpose and usefulness of design patterns.
I remember reading about design patterns for the first time in the late ’90s. It was a book called The Design Patterns Java Companion by James W. Cooper, and it described all of the Gang of Four patterns with examples in Java. At the time this book had a massive impact on the way I looked at problems and the way that I looked at code. I remember looking at the source code for Java’s Input/OutputStream hierarchy and thinking ‘What a great example of the decorator pattern’. I could add more capabilities to a stream just by wrapping it in another stream.
One thing the article does get right is describing design patterns as a way for developers to discuss complex solutions. When I am pair-programming I always find myself discussing implementation details using desing patterns as it is much easier to tell someone “Lets use the Observer pattern here to decouple changes in the data from the classes that need to act on it” than it is to describe the implementation step by step. No matter which domain you work in (e.g. finance, health, telecommunications etc.) the same fundamental concepts usually apply. You may have a class that needs to perform a calculation differently depending on the context it is being used in (Strategy pattern). Or you might be trying to develop a simple interface for a complex sub-system (Facade pattern).
If design patterns have supposedly flopped then why are they at the core of all of the software we depend on today? Spring MVCs DispatcherServlet is based on the Front Controller pattern (in fact MVC is a pattern too!). Most of the game AI used today is implemented using patterns such as State (to control the behaviour of NPCs) and Composite (to perform command queueing) to only name a few.
Design patterns have not flopped. Developers who cannot work out where a design pattern might help them solve a problem need to do a lot more reading and study a lot more code. Design patterns are one of the most important tools in a developers toolbox and a skilled craftsman should never blame his tools or in this case, not have the right tools for the job.