Skip to main content
Inspiring
March 13, 2009
Answered

CFC Methods and Code

  • March 13, 2009
  • 4 replies
  • 566 views
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.
This topic has been closed for replies.
Correct answer apocalipsis19
I figured this out by myself too!

Thank you Dan for your input!

4 replies

apocalipsis19AuthorCorrect answer
Inspiring
March 19, 2009
I figured this out by myself too!

Thank you Dan for your input!
Inspiring
March 19, 2009
I figured this out by self too!

Thank you Dan for your input!
Inspiring
March 17, 2009
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!
Inspiring
March 16, 2009
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.