I saw this article, where the author says that (and I’m paraphrasing here) he thinks that design patterns stifle creativity, and should not be used.
Which led me to the question: “In addition to learning design patterns by rote, and implementing them from memory in some twisted version of cut and paste, what can we learn from design patterns?”
Although I believe that there are many problems that should not be solved by forcing the problem domain into a pre-rolled solution, I also believe that design patterns do more good than harm.
I have always thought “What can I learn from this design pattern?” rather than “How can I force this piece of code to conform to this design pattern?” I personally find that the way of thinking that I learnt from studying design patterns has helped me enormously to write code that follows the accepted best practices of object orientation,long before I even knew that such things existed. The practices that I am referring to are things like the open / closed principle, the law of Demeter, the Liskov substitution principle, the single responsibility principle etc.
My contention is that by studying design patterns, you learn to solve problems in ways that automatically conform to these and other best practices, and as such will be easier to create, maintain, unit test etc.
And, for many common programming problems, design patterns already represent an industry standard method of solving them. Things like singletons, factories, command and strategies are software components that everyone should be using to solve the issues that they are meant to solve.
So, by all means, don’t fall into the trap of blindly obeying someone else’s solution because it is some sort of best practice. But, equally and perhaps even more importantly, don’t discount the benefits to be had from the open-minded study and usage of design patterns.