I was watching a talk by José Valim (the creator of Elixir) on using design patterns in Elixir and one thing he said was that design patterns are about problems and not solutions. They are a recognition that certain problems tend to occur a lot when developing software. While there is a solution for each pattern the emphasis should be placed on the problem.
What this means to me is that before using the solution part of a design pattern, you first have to recognize the problem. This means design patterns are reactive. You can’t architect using design patterns. You can only react to them when you see the problem in your code.
This is similar to the Rule of Three from the Refactoring book and popularize by Martin Fowler. It states that you should wait to see three instances of duplication before you refactor. This helps to insure that you are seeing the correct abstraction and not just guessing.
I remember going through an interview once and I was asked for my thoughts on design patterns. I stated that I believed they were something you refactored code to. The interviewer then stated that I was wrong and you should use them when architecting a system. While I understand what he was trying to say, I believed than and still believe that my answer was correct. And I think José Valim would back me up on that.

Leave a Reply