Sunday, June 15, 2008

Approaching patterns: Our mistakes

By definition patterns are to give solution of design problems.
Sometimes we don’t understand context and intent of problem that a design pattern conveys. Then we start using this pattern in a wrong way, in a wrong place, sometimes we got over enthusiastic about patterns. That results in a bad design.

Only mistake we did is we didn’t approached the pattern in right way. So it is very important how we meet Mr. X pattern. Definitely, we have to follow a pattern for studying a design pattern : D

Big Mistake :
Almost Every writer describes the purpose of the pattern in the first line. And readers push it hard to understand this very first sentence. And this causes the greatest disaster. (Applicable for newbies).

Bigger Mistake :
After understanding the purpose... (I don’t how many people get this actually) we directly move into the class diagram that shows the solution of the design problem. (Wow man, I got the problem in one sentence and solution in one diagram… I know 60% of the design pattern). Now let’s go through some example and then Mr. X pattern will be transparent to me.

This approach works for a few patterns (for Mr. Factory, Mr. Singleton…)

But reality is.. When we face real life problems….

  • They are sometimes so hidden that you cannot get into it in right time.
  • Some patterns are so related that you cannot distinguish.
  • There are alternative patterns for almost same problem.
  • Sometimes you are so enthusiastic about patterns, that you decide I must use this pattern then put the cork in wrong bottle.

Okay, don’t take it so hard. I have some pattern on learning pattern.

Did you wash your hand before eating?? You have to learn and realize some basic concepts to a good extent before you move to design patterns. If you are serious about a good design, you are gonna consider your pillar. Preferably, you should have nice understanding with OO concepts, interface, abstract, delegation. Can you please revise although you learnt what is interface?

(Poth pothiker srishti korena) Pedestrians create the path. Don’t try to map pattern names with problem definition at first. First face the problem, solve it your own way. Then look for the actual solution what pattern gurus do? That is how you become capable of solving a problem with help of Mr. X Pattern.

Are you doing well? Now, you have to consider these…

Ratul and Zico are twins. Both of them in love with Emmy? Nope. There are some patterns that are very common in structure but different in their use and intent. ( Strategy & Bridge Pattern )

On whom will you take the bet in wrestling? The agile one or the strong one? You will find many problems that have multiple solutions. You have to choose the right one so that you can appreciate yourself in the long run. ( Template Vs Strategy Pattern)

Dr. Zekyl &Mr Hyde. Get double minded. Convince yourself when you use a pattern in your design. When you have your own logic for why you’ll use this pattern, try to argue with yourself why you shouldn’t use this pattern. Believe me, this ensures that you don’t misuse patterns and you realize the intent of the pattern in the long run.

How about a cherry on your ice-cream. You may have understood the naive version of a pattern. There may exist improvements of the pattern. You can handle your problem smartly when you have known different version of Patterns. ( applying hook on Template pattern)

Now, if you ask me about a good design pattern book to start with, I will not tell GOF book. For starter “Head First Design patterns” is cool. And when you learn a design pattern don’t forget to google them.

2 comments:

masum.ahammed said...

Great!! I appreciate you...

Rubaiat said...

nice writing. waiting for more of your writings...