Skip to main content
Known Participant
June 5, 2009
Question

CFCs and the Presentation Layer

  • June 5, 2009
  • 3 replies
  • 588 views

Hi,

I am starting to get to grips with CF and have a few questions about using CFC's

At present I have a News module which has 3 major functions

-add news

-delete news

-update news

I have CFC with 3 methods, add, delete and update. What is the best practice for my cfm files

1) have 3 seperate cfm pages each calls the method it requires

2) have one page index.cfm with a case to output the form required (url.action=add, url.action=update, url.action=delete)

3) same as above but the forms are included in the method (lots of HTML in my CFCs)

They all work, 1 has more cfm pages, 2 has one but is a bit harder to read, 3 has one CFM also and keeps the CFM really clean but had loads of HTML in the CFC (a bad thing?)

I would be intersted in opinions on the best way to work.

Thanks,

H.

    This topic has been closed for replies.

    3 replies

    Inspiring
    June 5, 2009

    As usual, there is no "one true answer."  It's a trade-off, and it comes down to this:

    1. On the one hand, CFCs remove code from "the web page" (CFM), where it might be taking up a lot of space, and put it into a separate location where you can focus upon it when you want to, and completely ignore it when you want to.
    2. On the other, CFCs create "coupling" between different parts of the site which may or may not, given the situation, be a good thing.

    Given that there is no "bright-line rule" to be found here, my best advice is simply:  "whatever you do, plan what you do, and maintain that plan throughout the service-life of the application."  (Most likely, the application's tenure at the company will considerably out-live your own tenure at the same company, so your plan serves many distinct purposes.)  Contemplate your next move before you make it.

    Inspiring
    June 5, 2009

    Hi,

    I mainly use the first option, as to keep my sources easy to read (even for other people ! )

    You could also write a 4e method in the CFC, which does the logic for you :

    MutateNews: receives all necessary params to execute either method and the action param mentioned in point 2.

    Then you could do something like this :

    switch(action) {
         case "add" :
              call add news method
              break;
         case "update":
              call update method
              break;
         case "delete":
              call delete method
              break;
         default :
              return "no such action";
    }

    In this case you would have but one action page to call, which in turn calls the MutateNews method.

    It is useful in some cases but ultimately it is up to you which method you prefer. Neither is worse then the other.

    Cheers,

    Bert.

    Inspiring
    June 5, 2009

    Choose the method that is both simplest, and allows the most flexibility for changing requirements.