JavaRanch Home    
This page:         last edited 15 June 2005         What's Changed?         Edit

When To Apply Design Patterns   

A common question asked in forums is "I need to develop a system that does XYZ, which design pattern should I use?". Typically, though, this question can't be answered and shows a lack of understanding on how and when DesignPatterns can and should be applied.

The misunderstanding is that a DesignPattern is not a solution to a functional problem, but a solution to a design problem - a problem, that already speaks about classes and their relationships. From that follows that a good time to look for a patterns to apply is

  • when you are sketching/implementing a design and run into a problem - you don't like something about the design and look for patterns that resolve that problem, and
  • when you are sketching/implementing a design and find that something in there already resembles a pattern - then think about whether your design can benefit from moving it even more into the direction of the pattern, if only by naming classes accordingly.

Another thing to keep in mind is that the solution to a design problem doesn't always need to be a pattern. By only asking about a pattern to apply, you are unnecessarily restricting the types of solutions. Therefore, don't ask for patterns, ask for solutions. If someone thinks a pattern would help, he will tell you!


JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton