By Peter Bell

Design Patterns Debate

Great posting from Kola bemoaning the lack of critical thinking about design patterns in the CF world. Sean posts some interesting comments and then blogs about the topic some more.

This has been a pet peeve of mine for a long time and it is great to see a push towards a deeper review of the patterns used in the CF world and the strengths and weaknesses for different use cases.

For example, Sean commented that he typically doesn't use one manager per business object but per group of interacting business objects. I take the opposite approach and generate a service class for each business object. His solution allows you to create more elegant, well thought out and maintainable applications. Mine allows you to create a decently architected and maintainable app in however long it takes you to describe the properties of your business objects in XML (maybe 20 minutes)! I intend to build over 1,000 custom web applications next year. I'm guessing Sean is shooting for a few less. Different drivers, different approaches.

It is always really important to look at the forces that drive the selection of a pattern. To me it is also extremely important to continue to enrich the CF specific pattern literature by proposing heuristics (rules of thumb), documenting strengths and weaknesses of various patterns so future developers can more quickly access that experience and have more information to consider when deciding whether to use a pattern in a given situation.

Comments
Where can CF developers learn design patterns for solely web development? What are your recommendations ?
# Posted By Brad | 7/26/07 10:46 AM
While some patterns are web specific, there are many good design patterns that will help people designing web applications that aren't specific to web development. Start with the Gang of Four book - "Design Patterns" - or for an easier intro "Head First Design Patterns". "Refactoring to Patterns" is also good. I'd subscribe to Reddit.programming and keep an eye out for blog entries with titles you recognize from the books (singleton, observer, facade, factory, etc.) and google each pattern to see what comes up.

You might want to google "patterns of enterprise architecture" to see what Fowler had to say, and if you can afford it, the book is very good and has much more info than the website. Also google "J2EE design patterns" - good descrption of DAO, front controller and a bunch of other web specific patterns there.
# Posted By Peter Bell | 7/26/07 10:54 AM
Couldn't agree with you more! I think what is really missing is there isn't actually a definition of the said ColdFusion specific Design Patterns discussing the trades offs, alternatives and when it should be applied
# Posted By kola | 7/27/07 5:52 AM
Thanks for the recommendations! I guess that may take me few years to catch up with design patterns by reading books & blogs, study open source CF applications, and listen to experts!
# Posted By Brad | 7/27/07 9:13 AM
@Kola, Well, that's what I've been trying to do with my blog - looking at everything from Dependency Injection through GoF patterns, through recognized web patterns like DAOs, through "patterns" for handling product attributes, etc. Problem is, the blog is a discussion rather than a definitive reference, but there are definitely plenty of postings looking at the trade offs between various patterns and how/where you might choose to use them.

@Brad, It certainly takes a while, but just start with a pain point, learn a little, improve a bit and move on. If you have all your SQL in the views (say), put it into something, call if a DAO and see what happens. Then try wrapping it with a service class and making that the "api" for your model. Then try putting persistence methods in the business objects and then in the service class and note which works better for you (for remote access, you need a save() method in the service class, for instance. Then try using view helper CFCs for your views to get all the pagination and other concatenating stuff out of your CFML files to make them easier for designers to work with. It is just a matter of playing with things and making your code a little more maintainable every month. I'd just start with pain points (duplicated code, hard to maintain code, etc.) and look at what others are doing to solve those problems.
# Posted By Peter Bell | 7/27/07 9:41 AM
http://www.cfdesignpatterns.com seems to be a nice place to pick up on coldfusion design patterns
# Posted By Josh | 12/27/07 3:47 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.