Wednesday, June 5, 2013

7 Stages of Design Pattern Adoption

When I first read the “Gang of Four” book, one message in particular really hit home with me – software developers face problems, the same problems over and over again, and design patterns provide reusable solutions to those problems. And I thought “Wow! I’m a software developer. I have problems that need better solutions, bring it on!”. It wasn’t until later that the realization struck that design patterns, and their usage and adoption, are much more subtle than that.

At the beginning of my career, I was completely unaware of design patterns or SOLID principles, or even object-oriented programming. As I progressed and matured as a developer, it became obvious that I needed to find better ways to craft software. In that process I went through several stages of professional development leading to the eventual adoption and assimilation of design patterns into my coding process.

Stage 1: Denial

“Patterns? We don’t need no stinking patterns!”

Due to ignorance, inexperience, or resistance, many developers just flat refuse to invest time in learning about patterns, SOLID design principles, or the basic building blocks of object-oriented programming. This only serves to stifle their professional growth and credibility.

Stage 2: Curiosity

“So what were those design patterns you were telling me about?”

Eventually there comes a time when the tried and true methods of the novice developer run directly into a wall, or necessity leads them in search of new frontiers. The rot has overtaken the project and killed new development, created a maintenance nightmare, caused several to question their career decision, and accumulated a mountain of technical debt.

Stage 3: The Maslow's Hammer

“Get me some nails because I have a hammer, and its name is Strategy!”

New knowledge leads to excitement but can often lead to blinders. Until we’ve had time to disassemble the information, experiment with and implement it, and put in the requisite time to internalize it, the whole world looks like it fits into the (state your pattern name here) pattern.

Stage 4: Erudition

“Strategy does not work for everything. What else you got?”

Soon we realize that not all of our problems can be solved by, or forced to fit a single pattern. Now is the time for study. Not just study, but understanding, and for design patterns one of the most significant moments of eureka comes when you grasp the concept of intent. What is the intent of the pattern? What specific problem was identified as needing a solution and thus the pattern defined because of?

Stage 5: Restraint

“With great knowledge comes great responsibility”

The more seasoned pattern aficionado sparingly begins to introduce patterns that meet the specific criteria of the challenge they face into the domain. SOLID becomes more of a conscious decision. Analysis of the code and design becomes a deeper and richer experience.

Stage 6: Emergence

“First you learn the instrument, then you learn the music, then you forget all that and just play”

You have spent so much time, effort, energy, and erudition, that patterns naturally begin to find their way into your code. You still consciously recognize a Factory, Strategy, Fa├žade, or Proxy, but it is merely an acknowledgement of its existence rather than an effort to find a place to introduce a pattern. There is a measurable change and improvement in the quality and structure of the code and the coding process.

Stage 7: Mastery

“Those who call themselves masters are not masters”

At this level, ideas flow directly from your mind to the keyboard without hesitation, without impediment, and without fear. But the master is restless and never satisfied, always evaluating and re-evaluating where he is and how he can be better every moment. The master sees the code not in terms of methods or classes but as an organic system of maintainable order.