Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is better for UDFs: CFC vs CFM

I've several logically-related UDFs in a single file in my application.

The question is that should the single file be a CFC file or a CFM file? and Why?

I've referred to several links as below but they explain more about how to go about implementing the solution. All I want is to know is which one is better - CFM or CFC?

How do you organize your small reusable cffunctions?

http://blog.adamcameron.me/2012/07/which-is-better-having-your-methods.html

Thanks for helping.

like image 691
Crash OR Avatar asked Dec 08 '22 13:12

Crash OR


1 Answers

"Better" is subjective. If a collection of UDFs all work with the same data that you need to pass between them, they should probably be implemented as a CFC so one can have stateful objects so the data and the methods can be encapsulated in their own memory space.

If they're purely static methods, then an included library file might be fine.

INcluded UDFs pollute the variables scope individually, whereas functions in a CFC instance are accessed via the one object variable, so is a bit tidier.

If CFML had the concept of static methods, I'd always use CFCs, but as CFML doesn't have static methods, there's scope for justifying function libraries as well as CFCs.

Personally: I'd always use CFCs. They just seem more organised and more tidy.

like image 164
Adam Cameron Avatar answered Feb 03 '23 02:02

Adam Cameron