开发者

Should I Use CFINCLUDE or CFSAVECONTENT inside CFC

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 str开发者_Python百科ong 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.


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. :)


Do not blindly follow a pattern or methodology just because someone suggested it. Look at the needs that your site has and pay attention to your own preferences, with an eye toward someone else maintaining the code down the road.

Specifically, I use CFC's to encapsulate the interaction with the DB. I follow a MVC pattern because separating the view code from the model code is a very good idea, whether the CFCs are following true OO rules is less important.

I use cfincludes in many places to reduce redundency in my view layer.

I have implemented the controller portion of my pattern using a custom framework (I created the controller), then got smarter and used MachII, Fusebox and Model Glue. Each of these frameworks supports/encourages the use of CFC's views etc, or better stated that each supports good design and separation of concerns.

Find good patterns, decide what works for you, implement and document.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜