Should I use CFINCLUDE or CFSAVECONTENT inside CFCs

advertisements

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?


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.