CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeremy D. Miller -- The Shade Tree Developer

Under the hood and working with .Net, TDD, Software Design, and Agile Stuff

Just because it's in a patterns book...

I'm picking on a commenter here a little bit, and he probably didn't mean it this way, but it provided the impetus.

Don't ever assume a solution is correct for your problem just because it's a pattern in a book on your shelf.  Heck, the GoF book has a full chapter on the Singleton pattern, one of the leading sources of painfully tight coupling in enterprise systems.  Patterns are just things that reoccur in code.  Not good, not bad, just patterns.  Any given pattern is probably useful in certain situations and harmful in others.  Just because Fowler or the Gang of Four or the POSA guys wrote about a pattern doesn't magically make that pattern a good solution anywhere you feel like sprinkling it into your design.

When you learn about design patterns you absolutely have to pay attention to the discussion on when and why to use a pattern.  It also helps to understand the trade offs when there are competing patterns.



Comments

Joe Ocampo said:

Gospel vs Guidelines mentality.

A majority of our industry interprets guidelines as Gospel. Then we(coaches) spend the remainder of our time putting them through rehab.

# October 15, 2007 10:51 AM

Jeremy D. Miller said:

@Joe,

Very true.  As coaches though, we really need to explain "the why" anytime we give out any kind of guidance.

# October 15, 2007 11:27 AM

Jeff Doolittle said:

This is why I recommend Kerievsky's Refactoring to Patterns (www.amazon.com/.../0321213351).  

From page 29: "Good designers refactor in many directions, always with the goal of reaching a better design."

The goal should never be "wow, look at all the cool patterns I used" but rather, "look how I was able to use well-known practices to create an elegant and maintainable design."  Patterns for patterns' sake is folly.

# October 15, 2007 2:18 PM

Joe Ocampo said:

But what about the pattern thumper who has the GOF patterns memorized and strictly has a myopic view of the design.  He holds his GOF high in the air and sacrifices a key board and mouse to it every week.  All code must factor to the GOF there is no other way.  You will find peace and serenity in the GOF.  If it isn't in the GOF than you are going to hell!  Yeah that guy.

Let us pray now..... ahmmmmmmm ahhmmmmmm.

This takes him out of the job and goes against his very creed.

# October 15, 2007 4:10 PM

Object Bigot said:

In software development as in life, many people hold the persistent belief that there is one true book out there that will tell them all they need to know. If I can just find this book all my problems will be solved! Hallelujah!

People are basically lazy and have no interest in knowing 'why'. Someone should start a crusade to burn all copies of this GOF book. The Singleton pattern is pure evil and must be stopped at all costs!!

# October 15, 2007 8:47 PM

Russell Ball said:

@Jeremy - Well said.

"Value the Why over the How" should be one of the alt.net tenets. A solid principle that is misapplied has more potential to wreak havoc than all the drag-n-drop tools in the world. It also has the unfortunate side affect of turning people off to legitimate sources of knowledge like the GoF patterns because people get jaded after seeing them misapplied so often.

# October 15, 2007 10:48 PM

Jeff Brown said:

GoF offers a useful perspective on recurring design problems, it is not intended to be prescriptive.  If it were then I'm sure there'd be a spiffy "Refactor Now" button in your IDE to apply all of the *cough* "correct" refactorings for you.  ;-)

# October 16, 2007 2:51 AM

Glenn Block said:

People often forget that Patterns came second, not first. If you could read the 'Genesis' of Patterns it would be 'In the beginning there were solutions, then people looked at those solutions, saw common ways of solving problems and thus patterns were born". The reverse which is the misconception starts with something along the lines of "In the beginning there were patterns...".

# October 16, 2007 4:10 AM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# October 16, 2007 4:37 AM

Mark Heath said:

well said Jeremy

the Singleton pattern has singlehandedly turned the project I am working on into an horribly tightly coupled sprawling monster. its the only "design pattern" that many of the developers can name

# October 16, 2007 6:19 AM

Vikas Kerni said:

Patterns are solutions to a problem in a particular context.

Generally some people forget the context part.

# October 16, 2007 9:19 AM

Nikola Malovic said:

I totally agree that patterns should be treated more as principle and not as law.

For e.g., for me composite pattern is an type with the collection property of the same type, command is just a "traveling delegate" etc...

The patterns are common solutions to common problems, but they should be used only if there is no other "painless" way to do the same thing without patterns because they introduce additional complexity etc...  

# October 16, 2007 2:19 PM

book » Just because it's in a patterns book… said:

Pingback from  book » Just because it's in a patterns book…

# October 17, 2007 7:29 AM

Pawel Lesnikowski said:

It's not about the patterns but about refactoring to them.

That's why the Kerievsky's book is so good. It really helps you to create the ability to see paths in your code, that can take you to different patterns.

And as with paths in a wood, they can take you to a very gloomy and scary places.

But seeing those paths often helps in asking yourself a question "why?" Why should I implement  this in such way? Why is this solution better then the other one?

# October 17, 2007 10:18 AM

ThemePassion - Best stuff about design! » Just because it's in a patterns book… said:

Pingback from  ThemePassion - Best stuff about design! » Just because it's in a patterns book…

# October 29, 2007 10:48 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Jeremy D. Miller

Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy previously worked as a systems architect building mission critical supply chain software for a Fortune 100 company and learned agile development practices as a .Net consultant at ThoughtWorks, one of the pioneers of agile development. Jeremy is the author of the open source StructureMap (http://structuremap.sourceforge.net) tool for Dependency Injection with .Net and the forthcoming StoryTeller (http://storyteller.tigris.org) tool for supercharged FIT testing in .Net. Jeremy's thoughts on just about everything software related can be found on his weblog "The Shade Tree Developer" at http://codebetter.com/blogs/jeremy.miller, part of the popular CodeBetter site. Jeremy is a Microsoft MVP for C#. Check out Devlicio.us!

This Blog

Syndication

News

All opinions expressed here constitute my (Jeremy D. Miller's) personal opinion, and do not necessarily represent the opinion of any other organization or person, including (but not limited to) my fellow employees, my employer, its clients or their agents.

About Me

"Best Of" Compendium

StructureMap (Dependency Injection for .Net)

StoryTeller (Supercharged Fit)

Build your own Cab

TestDriven

MVP