Tuesday, September 05, 2006

What are Software Patterns

What is a Pattern

A common definition of a pattern is that it is a solution to a problem in a context. That's a definition that's always struck me as being rather unhelpful.

For me a pattern is primarily a way to chunk up advice about a topic. Chunking is important because there's such a huge amount of knowledge you need to write software. As a result there needs be ways to divide knowledge up so you don't need to remember it all - what you need is to be able to get at a particular chunk of knowledge when you need it. Only then do you need details.

The solution provides a useful focus for the chunking. With some young eager programmer asking some grizzly veteran (i.e. anyone over thirty) how to deal with a particular situation and hear the veteran say "oh - you'll need an identity map there". The colleague can then look up identity map in some suitable patterns book.

So to make this chunking work each pattern should name a solution. This solution should be concrete, at least at the level of discussion we are talking about. You should be able to go away and use the pattern once you're given the reference. If you're successful the name should enter the vocabulary of the profession. It can take a while to do this, but when you say 'decorator' any reasonable professional should know what you mean.

Patterns should have recurrence, which means the solution must be applicable in lots of different situations. If you are talking about something that's a one-off, then it's not adding the name to the profession's vocabulary.

One of the interesting things here is that a singular solution can often lead to a recurrent pattern. This usually crops up when you see two different singular solutions which look completely different on the surface, yet have a deeper similarity - what Christopher Alexander refers to as the "core of solution".

Why are Patterns important?

One of the quotes that I find particularly appealing when I think about the need for patterns that that part of interest in patterns came from "...observations that projects fail despite the latest technology for lack of ordinary solutions"[PLoPD 1]. Patterns provide a way to organize and name those ordinary solutions to make it easier for people to use them.

Since these solutions are ordinary, it's common that experts in a field won't find anything new in a patterns book. For such people the biggest value of a patterns book is to help them to pass on the solutions to their colleagues.

Important Parts of Patterns

Anyone who takes a look at patterns is usually struck by the fact that most patterns are written using a regular form. Once you look at two sets of patterns you realize hardly ever do two patterns authors use the same form. The different patterns forms all have particular qualities to them, and any patterns author will tend to pick a form that works well with their innate preferences.

Despite the various forms, most patterns do have common elements. I'll talk about the different forms later on, but I think that's easier to do if I cover some general principles first.

Patterns are Solutions

Almost anything written about patterns has a definition that reads something like "a pattern is a solution to a problem". While I don't disagree with that statement, I think it does tend to under-emphasize the point that patterns are primarily about solutions.

I think it's important to say this, because there is a certain mystique that tends to embroil patterns. To cut through that mystique never forget that the whole point of writing a pattern is to describe a recurring and useful solution. Success is all about doing that in a way that others can replicate that solution when it's appropriate. Everything else is secondary - which means that however you choose to write the pattern, whatever form you take - all has to support this. Too often I've seen patterns writers, including myself, get lost in a particular format and lose sight of this simple priority. So whenever writing is getting difficult, remember it's the solution that counts.

Find more on Software patterns

Tags: software patterns, programmer

Can't find what you're looking for? Try Google Search!
Google
 
Web eshwar123.blogspot.com

Comments on "What are Software Patterns"