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.
"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With