tags:

views:

216

answers:

3

It seems like the standard MVC approch (as it relates to ColdFusion) is to make the view files .cfm and do a CFINCLUDE inside of the cfc that ultimately processes the view.

Does this break the Object Orientation of cfc's?

Does this cause the CFML compiler to have to compile the view everytime?

Is there a strong reason to NOT make the view files themselves cfc's with a GetContent method?

+3  A: 

If you're interested in implementing MVC, you should check out the wide array of CFML frameworks that already make these decisions for you.

Try ColdBox, ColdFusion on Wheels, Mach-II, or Model-Glue. Or at least take a look at their source code and see how they handle it. :)

Chris Peters
Sean Cornfeld's Framework 1 http://fw1.riaforge.org/ looks very interesting too
kevink
I'm looking more for why the frameworks made the decisions that they made rather than what decisions they made.
Tom Hubbard
Gotcha. I don't have any direct experience with this, but I hear that <cfsavecontent> doesn't scale well for large sites. Not sure what the reasoning was, but I vaguely remember it coming from someone credible. Do with that what you will. ;)
Chris Peters
A: 

Wouldn't CFInclude tie down your CFC portability more by coupling it directly to a CFM.

jfrobishow
+3  A: 

Does this break the Object Orientation of cfc's?

Achieving this vague "Object Orientation" of cfcs is kind of subjective. Forcing yourself into "everything must be an object" is going to force you into doing things with CF that will create extra overhead. I little compromise is needed to make sure apps are speedy and efficient. Don't worry about achieving some undefinable goal of being "object oriented". Make a more definable goal, such as achieving reuse of cfcs, or encapsulation of change. Trying to make views into objects isn't necessarily help you achieve those goals because every view will be different and probably not reusable.

Does this cause the CFML compiler to have to compile the view everytime?

Cfms are compiled and cached too. I've had several large forms consisting of tabs, where each tab is a separate cfm file. On the first load, they take a couple seconds to compile and display. On subsequent loads, the tabbed view is generated and displayed instantly. The same happens with cfcs.

Is there a strong reason to NOT make the view files themselves cfc's with a GetContent method?

I while ago I tried implementing my own framework just for the learning experience and I ended up with the cfinclude approach. From what I remember, what I found was that using cfinclude encapsulated things better and avoided the cumbersomeness of creating objects, passing around arguments needed for the view, worrying about objects being in the right scope, and avoided the extra overhead of creating view objects.

In the end though, I suppose this is one of those things you have to try yourself to figure out what approach is best for your situation.

Jayson