Tuesday, 6 March 2007

Introduction to Patterns (Week - 1)

Today was the first lecture of Patterns for Software Design, before going into actual detail Dr. Sri gave us a summary of what patterns are and how they help us in real life.
During lecture, we discussed how the idea of patterns was put forward by Christopher Alexander.

After today’s lecture about patterns, my understanding says that patterns are answers to a problem in a context provided the problem is reoccurring. A same problem can crop up numerous times over a period of time, so instead of designing a solution every time, existing solutions can be utilized.

The aim of developing patterns is to;

Reduce the problem solving technique – if a problem is encountered and we have the solution already designed, then it saves time for the developer
Provide reusable solutions – solutions are reusable and can be used for same kind of problem
Solve specific problems – solutions are to one specific problem i.e. same context
Act as template – reusable solution act as a template


Patterns can be found in our daily lives as well, we follow different patterns but we do not realize them until we study about patterns, like we all have work patterns, traveling patterns, building patters, eating patterns etc

One such example of a real life pattern would be;

Context
Mr. Thompson is going on holidays with his family, cruising along M25, suddenly Mr. Thompson hear a strange sound coming from one of the rear tires of the car. He stops the car and sees a flat tire. Checking the boot of the car, he finds out that he doesn’t have the Jack to change the tire. Now Mr. Thompson can not leave his family in the middle of the road and he is not even registered with RAC so that he can call them for help.

Problem
How to replace flat tire?

Solution
In this situation Mr. Thompson should wait for any car passing by for helping him out or wait for police. Waiting for another passer or police wouldn’t take long as M25 is a busy motorway. To avoid any future accident, he should check car boot for all necessary equipment especially before going on a long journey and should get himself registered with RAC.



5 comments:

Bash said...

Very well explained. Example was pretty cool :)

richie rich said...

Well done mate your explanation on patterns was quite good. What you did not say was the problem had to be within the same context all the time for the pattern to work. This is the problem i have with patterns once the context or environment changes sligthly the pattern is unapplicable.

With you example quite funny but i was not to sure what your solution was if its waiting on the police or passerby driver or checking to see if you have all the equipment before he leave home.

Abbas said...

I am jst ebing versatile and that's why i gave three different solutions lol.

Thanks for highlighting that context part though :)

Anonymous said...

Hi khawar

just to be a bit more illustrative on what richard said, I would say that your problem is perhaps too broad to be in a context of a pattern, there are a lots of things those you would have to do in context such as the road must be a busy one etc, but overall good work well done

Abbas said...

Hey waseem, thanks for comment..
Yeah I understand your and Richard's point of view.

A problem within one context can have more than one solution and since there is no governing body which can decide, which solution is the best for a particular problem, so people working in different environments can come up with different solutions for same problem
Now in the example I gave, having more than one solution is not a big deal, but I agree with you and Richard that the problem context i posted slightly went broader.

Anyways thanks for your comments guys...