What is better for UDF: CFC vs CFM

I have several logically related UDFs in one file in my application.

The question is, should one file be a CFC file or CFM file? and why?

I mentioned a few links as shown below, but they explain more about how to implement the implementation. All I want to know is which one is better - CFM or CFC?

How do you organize your small re-work?

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

Thanks for the help.

+4
source share
2 answers

"Better" is subjective. If the UDF collection works with the same data that you need to pass between them, it probably should be implemented as CFC, so you can have stateful objects so that the data and methods can be encapsulated in their own memory space.

If they are purely static methods, then the library-enabled file may be right.

INCluded UDFs pollute the scope of variables separately, while functions in a CFC instance are accessible through a single object variable, so it’s a bit tidier.

If CFML had the concept of static methods, I would always use CFC, but since CFML has no static methods, there is an opportunity to justify function libraries, as well as for CFC.

Personally: I will always use CFCs. They just seem more organized and tidy.

+12
source

Based on my experience, I would prefer CFCs. Bear in mind that most UDFs are just helper assistants, so you only need to create them once. Placing them in CFC means that you can load them into the application area and save an instance of CFC. UDFs are created only once for your application. In addition, you could use other CFC extensions of this β€œuseful” CFC to make UDFs available too.

Now with CFM, when you include this template, UDFs are created again for this request. This is an extra treatment for something that really doesn't need it. Plus, what has already been mentioned around UDFs polluting the scope of variables is another big reason for CFC preference.

+2
source

Source: https://habr.com/ru/post/1500897/


All Articles