Design Patterns Series 21 - How to create your own pattern?

By this post we finish our design pattern series. This post gives you a guide for how to build your own pattern in ten easy steps. Just follow along, and you are on the route to fame and fortune.

If you don't see an established design pattern where you think there should be one?. You can create your own design pattern, and you can publicize that pattern, getting it into design pattern repositories around the world.

Remember, design patterns are supposed to make solutions easier. Don't create a design pattern just for the sake of creating a new pattern if it's not going to be helpful. After all, patterns are supposed to be tools, not hindrances.

Pattern Catalog Style :

The best way to start anything is with a guide of some kind, and for design patterns, that guide is the Pattern Catalog Style. There are ten sections in a pattern catalog style :
  1. Intent
  2. Motivation
  3. Applicability
  4. Structure
  5. Participants
  6. Collaborations
  7. Consequences
  8. Implementation/Sample Code
  9. Known Uses
  10. Related Patterns
In the Gang Of Four, each of the 23 patterns is written in a catalog style, with each of these ten topics carefully covered for each pattern in the Gang Of Four book.

1- Intent
The Intent design pattern catalog entry describes the pattern and what it is supposed to do. This is a short overview of the pattern that someone is supposed to be able to read and understand to know if the pattern solves her problem.

When you write the intent of a pattern, keep it simple, even if it means not including every little detail. This is an overview of your patten, sort of like the descriptions in TV guide, that lets readers know if they are going to interested in your pattern.

2- Motivation
The motivation section of design pattern catalog entry lists a scenario that describes the problem the pattern is supposed to solve, using a concrete scenario.

3- Applicability
The applicability section of pattern's catalog entry describes scenarios where a pattern can be applied. You usually provide a set of condition - and if a problem meets those conditions, your pattern is a good candidate to solve it.

4- Structure
The structure section usually shows a diagram indicating how the pattern works.

5- Participants
The participants section lists the classes and objects that take part in the pattern,as well as their roles. To create the objects, for instance, you might want to make sure they all use the same methods - so you should have an interface. And you should list the classes that implement that interface, as well as the client code that attempts to use them.

6- Collaborations
The collaboration section entry indicates how the participants work together.

7- Consequences
The consequences section lists both the good and the bad effects of the pattern. Your pattern, being the most advanced and excellent one the world has yet seen, may not have any apparent drawbacks, but think hard on this point - it would not be good if you steered someone into using your pattern if that pattern's going to cause him problems.

8- Implementation/Sample Code
The Implementation/Sample Code section outlines the techniques you use when implementing this pattern and/or sample code.

9- Known Uses
The Known Uses section gives some real-world examples where the pattern has been used.

10- Related Patterns
The related patterns sections lists other patterns that might be related to this one.

Congratulations - you have created your own new pattern. All you have got to do now is to submit your own pattern catalog entry to a design pattern repository such as the Portland Pattern Repository, as hosted by Cunningham & Cunningham at http://www.c2.com

Comments

Popular posts from this blog

ASP.Net MVC : ActionLink with bootstrap icon

ASP.Net MVC : Conditional Validation using ValidationAttribute

Android : How to change progress bar color at runtime programmatically?