Saturday, December 1, 2012

Basics of Design Patterns!!!

A good design saves a lot of coding issues while providing you better code re-usability and maintainability - Mostly used phrase in Software Industry. While some follow it and some simply don't care.

Hey, I got stuck somewhere !!! I need a solution to do this !
Not only you but billions of the Developers out there face some problems. And why only talking about Software Developers ?
Anyone in this world has to face some kind of challenges in their own field of work. May it be a Software Developer, may it be a Civil Engineer, may it be an Electrical Engineer or may it be anyone.

So, what's the point here ?
The point here is very much simple, we face problem and seek solution. In Software Industry also, some solution approach is defined to have some control over the problem we face. Those are known as Design Patterns.

Well, good enough So, what are they ?
Design Pattern: Design Pattern is a general reusable, time-tested solution to a set of commonly occurring problems. This is just a guide to follow to save your application from creating the mess that has already done by many a few earlier.
Design patterns are extensions to OOP.

What if, I don't follow them ?
No problem, at all. You are not bound to follow them. You are a free bird while it comes to your application. But with your application growing, you can gradually feel the urge to incorporate Design Pattern in your application.

OK. I am a newbie in Java. Should I also follow them ?
Hey, no one except JVM is a 100% Guru in Java. No one, can wholly master any language or platform. But, you need the basic concept of OOP and some exposure to real world problems to relate and incorporate Design Pattern in your work. If you are a professional Developer, you might have get some knowledge already while working.

Where did this hell come from ?
Its not from Software Industry. The idea of design pattern came from an architecture industry. back in 1977 Christopher Alexander, a civil engineer wrote about his experience in solving design issues with some design constructs which proved to be successful over time and lead to desired desired effect. So, he thought of the benefit of society and documented them for other's use.
How good he was.
In Software Industry this first came to existence in 1987 when Kent Beck and Ward Cunningham began experimenting with the idea of applying patterns to programming and presented their results at the OOPSLA conference that year.
But design patterns gained popularity in 1995 with the Gang of Four (popularly known as, GoF) with the creation of  Design Patterns: Elements of Reusable Object-Oriented SoftwareAddison-WesleyISBN 0-201-63361-2.
Gang of Four members: Gamma, ErichRichard HelmRalph Johnson, and John Vlissides

What I am supposed to do with them ?
As per the definition, design pattern is a guide to some commonly known problems. If you follow the guide, you are supposed be avoiding many situation that causes nightmare and also can speed up your development process.

OK. are there any well known example you can provide ?
There are many. Java itself follows many design patterns on its own. While framework based on Java like Spring, Hibernate, GWT, JSF use many design patterns. I am listing a few here,
Java: Observer Pattern for Event Listeners
Java: Composite Pattern for File and XMLReader utilities
Java: Decorator pattern for I/O
Hibernate: Factory pattern in SessionFactory
JSF: JSF is based on the concept of MVC pattern

OK, you take a lot of name. What are they ?
They are actually design patterns used in different scenarios while working with Java. Good news is that, you also have followed design patterns in your code unknowingly like, Interface pattern, Abstract Parent Class pattern etc.

OK, I got it. So what next ?
Seems like, you got some interest in this !!!
Great...
I will now move on to different types of patterns in my next article.
Palash Kanti Kundu

No comments:

Post a Comment