Archive

Archive for September, 2009

Integrating design patterns "just before they become useful"

I recently commented on a provocative post by Jovan Sranojlovic called “Do Not Use Design Patterns Upfront” He made some thoughtful observations on why design patterns are important to software engineering and how they can a abused in that context as well. However, I disagreed with his basic thesis that design pattern should only be applied in a code refactoring context and not before. Based on his argument, thinking in design patterns upfront, based on the intent and purpose of code in not good, and even harmful. I tweeted my disagreement with a link to JUnit A Cook’s Tour, an example of, what I thought was, thinking in design patterns at the application design stage. The resulting tweet stream follows:

“Do Not Use Design Patterns Upfront” http://tr.im/uI3a – I don’t agree. Beck & Gamma did just that with JUnit http://tr.im/uI3z #asdp
1:09 AM Jul 30th by @chandimac

@chandimac no we didn’t. we explained junit with patterns, but we started with one tiny test and grew the whole thing from there.
6:33 AM Jul 30th by @kentbeck in reply to @chandimac

@kentbeck TX for the clarification. Do you recommend “thinking in patterns” early or should they be added at a later refactoring stage?
6:30 AM Jul 31st by @chandimac in reply to @kentbeck

@chandimac i prefer to put patterns in place just before they become useful. if i can’t see how to do that, then soon after.
6:51 AM Jul 31st by @kentbeck in reply to @chandimac

JUnit A Cook’s Tour explains the design of a system by starting with nothing and applying patterns, one after another, until you have the architecture of the system. As Kent pointed out, the article was written that way, and I had incorrectly assumed that JUnit was developed that way as well.

Design Pattern wisdom in 140 characters

I put patterns in place just before they become useful. If I can’t see how to do that, then soon after.

– Kent Beck

I was quite intrigued by Kent’s reply to my follow up question. It got me thinking about a bunch of issues. What does it mean for a design pattern to be “useful?” How much before is “just before?” What does it mean to “put patterns in place?”

I was so intrigued that I re-read a bunch of stuff on refactoring and design patterns by Beck, Gamma, Kerievsky and Alexander. I try my best to answer some of the questions raised in the remainder of this post – or more appropriately, reconcile some of my cognitive dissonance. Read more…

Share

Saint Singleton: Have We Martyred a Design Pattern Unfairly?

September 1, 2009 30 comments
Saint Singleton

Saint Singleton

In our book, I wrote the chapter on the Singleton Design Pattern, and on this blog I penned the post entitled, Singletons Give You Pimples. My comments were based on several articles (including one similarly named!) I had read on why to avoid the Singleton and the 2006 OOPSLA meetings in Portland, Oregon. Of the articles available online that detail the problems with the Singleton Miško Hevery’s blog post, Singletons are Pathological Liars is the most detailed, but Scott Densmore’s article, Why Singletons are Evil is an equally convincing—and succinct— argument why we should keep our distance from Singletons.

Even Erich Gamma was quoted as lamenting the fact that they included the Singleton in their Design Pattern book. There’s not a lot more that I can say than I did in my ranting post on Stinkin’ Singletons, and you can find tons more online.

Is There Salvation?

Recently on this blog, my old friend aYo Binite (who got me involved in ActionScript 3.0 design patterns in the first place) suggested that the Singleton wasn’t as bad as I made it out to be. Naturally, I replied with a reasonable argument comparing them to skin-eating viruses, pedophiles, and Nazis. aYo said that the jury was still out, and I wondered, ‘What jury?’ All in all, though, I may have been as unfair to the Singleton as the Roman emperor Diocletian was to Saint Sebastian. (Diocletian first had Sebastian used for archery practice and left him for dead. Then when the emperor found that he had survived—he had Sebastian beaten to death and thrown into a crapper.) Naturally, I don’t want to be equated with the touchy Diocletian, and so I’m offering up an opportunity for comments by our readers to either help pull the Singleton out of the crapper or shoot another arrow into the misguided design pattern. The Comment Section is Open!

Share
Categories: Singleton