Viewing By Day : November 8, 2004 / Main
November 8, 2004
More Thoughts on Design Patterns In ColdFusion
I've been getting asked quite a bit lately about using Design Patterns in ColdFusion. It seems that a lot more people are reading up on them, but are often having a more difficult time figuring out both how and when to actually implement them within their ColdFusion applications.

I think it's important for developers to approach the use of design patterns not from a "which patterns can I use in my application", or "I want to use the strategy pattern in an application" approach, but rather from a solid architectural approach. That is, I think it's more productive for developers to first model their application, then look for patterns that help solve problems within that model. Of course in order to do this, you first need a good understanding of what the most common design patterns are, and how they can be used in an application. One of the biggest pitfalls to avoid up front, though, is simply learning a pattern and then doing the equivalent of a copy/paste into your applications. Patterns are not absolute, and a pattern that fits well in one situation may not fit the same way into all of your applications. The only way to really understand design patterns, and how to apply them in your applications comes through study and experience.

So, where does this leave us as ColdFusion developers? Most of the design pattern literature out there deals with implementing design patterns in languages such as C/C++, or Java, or sometimes even pseudo-code. That's ok if you understand those languages, especially if you are able to make the connection between how it's done in another language, and how that maps to ColdFusion and CFCs.

If you read the ColdFusion Developers Journal, you may have noticed that design patterns are being discussed in more and more articles. What i would suggest doing if you are interested in incorporating design patterns into your ColdFusion development is to purchase one of the popular design pattern books, and use it as a guide when reading some of the various ColdFusion specific design pattern articles. I think that taking this approach will allow a lot of ColdFusion developers, with no experience with other languages to make the most of the information that's out there, and to ease their way into the world of design patterns.

To get you started, here's an excerpt from the book Design Patterns: Elements of Reusable Object Oriented Software. This book, by the so called "Gang of Four" is considered the seminal work on software design patterns. The excerpt (chapter 1) is hosted on Macromedia's site and introduces Design Patterns and lists out some of the more common one's you are likely to encounter.

Once you have the introduction to design patterns out of the way, here are some of the ColdFusion design pattern articles worth taking a look at:

Template Method Pattern
Iterator Pattern
Strategy Pattern
Composite Pattern
More on Composition
More on Polymorphism
Singleton Pattern
Creational Patterns
Facade Pattern
Data Transfer Hash Pattern

If you couple these with one or more of the following books, I think you'll have a good starting point:

Headfirst Design Patterns
Design Patterns: Elements of Reusable Object Oriented Software (Gang of Four)
Design Patterns Explained: A New Perspective on Object-Oriented Design

I'd definitely like to see more design pattern articles focused on ColdFusion. If you would too, why not drop the ColdFusion Developers Journal editor, Simon Horwith, an email over at simon(at)horwith(dot)com and let him know you would like to see more coverage in the magazine.