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

CFC Methods and Code

Participant ,
Mar 13, 2009 Mar 13, 2009

Copy link to clipboard

Copied

Hello Community!

I was asked to create a CFC that will encapsulate together the methods that as of today my company has in 3 different files. Each one of these file is included in the main program as a template using cfinclude. When I opened the 3 files, I noticed that the first 150 lines of code were exactly the same. The only thing that changed in the 3 of them were the methods after those blocks of code.

Before I ask my question let me explain how I am laying out my code:

<cfcomponent displayname="" hint="">

code that was common in the 3 places
code that was common in the 3 places
code that was common in the 3 places
code that was common in the 3 places
code that was common in the 3 places

method 1
method 1 code
method 1 code
method 1 codd

method 2
method 2 code
method 2 code
method 2 code

method 3
method 3 code
method 3 code
method 3 code

<cfcomponent>

Ok, I want to know if everytime I call one of my methods the 'code that was common in the 3 places
' will get executed or if I have to put that code in another method that gets called everytime I call the others. I want an idea to complete this task. I have created CFCs before but this is the first time I face a situation where I have to make such decisions.

Thanks!

Ysais.
TOPICS
Advanced techniques

Views

488

Translate

Translate

Report

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

correct answers 1 Correct answer

Participant , Mar 19, 2009 Mar 19, 2009
I figured this out by myself too!

Thank you Dan for your input!

Votes

Translate

Translate
LEGEND ,
Mar 15, 2009 Mar 15, 2009

Copy link to clipboard

Copied

The way you describe your code layout is ok. Whether or not you can improve upon it depends on what those 150 lines do.

Whether or not those 150 lines get called each time you use a function depends on how you call them. If you use cfinvoke, they get executed each time. If you use createobject or cfobject, they only get executed once.

Votes

Translate

Translate

Report

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
Participant ,
Mar 17, 2009 Mar 17, 2009

Copy link to clipboard

Copied

Thanks Dan!

I am having an issue now. All of my variables in the variables scope are nor being read in my methods; thus my program crashes.

<cfcomponent displayname="" hint="">

code that was common in the 3 places
code that was common in the 3 places
code that was common in the 3 places
code that was common in the 3 places
code that was common in the 3 places
Declaration of Variables
Declaration of Variables
Declaration of Variables

method 1
method 1 code
method 1 code
method 1 codd

method 2
method 2 code
method 2 code
method 2 code

method 3
method 3 code
method 3 code
method 3 code

<cfcomponent>

I am declaring my variables in the variables scope at the top of my CFC as you can see in the sample representation of my code.

Does it look weird or is that OK?

Thanks!

Votes

Translate

Translate

Report

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
Participant ,
Mar 19, 2009 Mar 19, 2009

Copy link to clipboard

Copied

I figured this out by self too!

Thank you Dan for your input!

Votes

Translate

Translate

Report

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
Participant ,
Mar 19, 2009 Mar 19, 2009

Copy link to clipboard

Copied

LATEST
I figured this out by myself too!

Thank you Dan for your input!

Votes

Translate

Translate

Report

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
Documentation