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.

Advertisements

2 thoughts on “What can we learn from design patterns?

  1. Sounds good to me. In fact, thinking about it, there’s a trade off of advice to give people. The earlier you are in your programming career, the more important it is to pay close attention to patterns, both to avoid reinventing wheels otherwise, and to become familiar with the reasons for the patterns. Hopefully you’ll take the right half of what you learnt forward (ie the reasons, not the patterns).

  2. @Alex – Thanks for stopping by 😀

    I like your thought that the stage of your career should inform how creative you get with pre-rolled design patterns, that is definitely a viewpoint that I agree with.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s