Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using external utility functions inside a CFC

New Here ,
Jul 24, 2008 Jul 24, 2008
I tend to write my code in cfscript whenever possible, but because not all tags are available within cfscript, I often have to write wrapper functions for them. I also have a bunch of miscellaneous, non-application-specific utility functions that I use quite a bit.

My ideal CFC is one that is completely stand-alone. Totally encapsulated. Something I could post here that would work for any other ColdFusion programmer without any fuss. However, if I want to use my wrapper functions and/or utility functions inside them, I lose the "stand-alone-ness" of it, because all of a sudden it is dependent on these external utility functions -- functions which, in my opinion, should be part of ColdFusion itself. I could define them in the cfc itself, but I don't want ten to twenty different versions of the same functions floating around in my application. Another option: I could require that they be passed in during the init() method, but there you go again -- it's not standalone.

So, my question is, how important is encapsulation to you? Do you think the benefit is so great that you would even avoid using simple wrapper functions and utility functions inside cfc's, or are you willing to strap on a few "dependencies" in order to write cleaner, easier code inside them?
TOPICS
Advanced techniques
302
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 24, 2008 Jul 24, 2008
Encapsulation is not important to me at all. I see two uses for cfc's. One is to make code re-useable. The other is make cf code available to a non-cf app.

I have no qualms whatsoever about invoking a function from cfc_number_2 in cfc_number_1.

I also have no qualms about using cfc's as function libraries. To be frank, that's what most of mine are.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 24, 2008 Jul 24, 2008
I think it's very important to not let dogmatic adherence to rules get in
the way of common sense and productivity.

Plus it's completely normal for programming components to have dependencies
on other programming components.

How many Java classes - for example - do you know that *don't* start with a
few import statements? Also how often are Java solutions distributed as a
single class, as opposed to a jar file? Why do you think that is? Because
the jar file gathers together a bunch of files all of which depend on one
another to varying degrees.

Why would you expect a CF-based solution to be any different?

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 25, 2008 Jul 25, 2008
LATEST
Thanks for the feedback. Yes, it does help to see that encapsulation isn't always the highest priority. Or perhaps I need to expand my definition of "encapsulation" to include *groups* of CFC's, which, together, are "stand-alone."
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources