Monday, February 18, 2008

The Elements of Design

In the world of software design, there are 3 distinct classes of "pattern" to be aware of:
  1. Smells
  2. Patterns
  3. Principles
The focus of each of these is primarily on enabling code to be changed and understood.

Smells are symptoms that are frequently demonstrated by code which has not been well designed. These are good to be aware of as they indicate you should probably consider doing something to fix the code so it doesn't smell so bad anymore.

Patterns are common OO design techniques for accomplishing certain behaviors. They were originally captured in the "Design Patterns" book by the "Gang of Four." These are very helpful, less for how they can improve your code, and more as a communication technique between developers. Personally I've found Singleton, Strategy/State, and Mediator to be the most far reaching. These are about as close as Computer Science has come to having terminology that can be used to describe abstract code design concepts. In general, you might fix a code smell with a Design Pattern.

Principles are a cross between smells and patterns except instead of telling you what is bad they tell you what is good, and instead of giving you precise designs to accomplish tasks they tell you what, in general, good looks like in Object Oriented languages. Of all of the three classes, Principles are probably the most useful because they describe design in general. Interestingly, they seem to be less known. Probably because they are both newer and slightly harder to understand. Of these, I have found the Single Responsibility Pattern and the Dependency Inversion Principle to be the most far reaching.

1 comment:

  1. Nice clear post.

    I have found the decision making process the hardest for these. It is easy to know "something is wrong" and it is easy to have lots of tools in the tool chest, but deciding which one to use and weighing the various pros/cons is the hard part.

    I think some blogs/articles preach knowing design patterns too much and not enough general good guidelines and practices. Patterns are great, but they don't solve everything and they focus on solving programming problems and not business problems. Perfectly designed code that doesn't do what the business wants, its still crud :-)

    Just like Lang used to push .... if it doesn't do what I asked it to do, it doesn't matter how long you worked on it. :-p

    ReplyDelete

Note: Only a member of this blog may post a comment.