An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Design Patterns in ColdFusion

December 4, 2003 ·

A thread on the Mach II forums raised the topic of design patterns, in particular the Composite View pattern. One of the strategies recommended in the Mach II Development Guide for managing views is to break your view down into a 'grid' of sub-views and define each of those as a <page-view> in Mach II, then use a 'layout view' to assemble the final page. In Mach II, this leads to your event handlers having a series of <view-page> tags that render HTML to contentKeys followed by a final <view-page> that invokes a layout view to assemble the page.
Reading through the Composite View pattern, it's interesting to compare the JSP / J2EE approach with the Mach II approach. In my opinion, the JSP / J2EE approach is harder to read and substantially more complex - in nearly all of its myriad forms - than the equivalent in CF / Mach II. Most of the suggested JSP / J2EE implementations are also less flexible - Mach II, by definition, uses late-binding of the sub-views in a totally dynamic way. That's not only more flexible but, in the context of CF, pretty darned efficient too. Most of the JSP / J2EE implementations end up hardcoding the sub-view filenames into the layout (composite) view.
By contrast, CF / Mach II lets you define a composite view that refers only to request variables which are populated by the controller. This lets you reuse composite views with different sub-views. You can also rename view files without changing any CF code in any other views - you simply change the one line that defines the view. The other big difference is that in all of the JSP / J2EE composite views, there is some JSP logic - code required to manage inclusion of the sub-views. Mach II's approach keeps that logic out of the views, placing it in the controller.
The bottom line is that it's useful to be aware of the J2EE patterns but beware of slavishly applying them to ColdFusion - some of them were designed to solve problems that are specific to the Java technology and you can often find a more elegant form of the solution in ColdFusion.

Tags: coldfusion · machii

3 responses

  • 1 Nando // Sep 8, 2004 at 5:04 PM

    I like the last sentence!
  • 2 Vui Lo // Sep 8, 2004 at 5:04 PM

    Without any doubt, ColdFusion is still the superior platform for front-end development since its inception. JSP is only catching up slowly. In fact, at its current stage, it can't even beat what ColdFusion 4 offered on customed tags. With Mach-II as back-end MVC framework, CFMX certainly is destined to become a superior platform for both front-end and back-end solutions.
  • 3 kwang // Sep 8, 2004 at 5:04 PM

    JSP sucks. Plain and simple. It's such a half assed effort, it's embarrassing.&lt;br /&gt;&lt;br /&gt;For front end stuff, CF and ASP.NET are the two clear leaders.