>Yeh, I'd go with that. Not overkill at all and good thinking. If you also
>have mini app specific checks, you could extend the 'global' cfc too.
>
>And apologies for souding like a patronising git, I misread you as not
>having used cfcs in an app before ;)

Lol, didn't take it that way at all. I just didn't want my initial post to be 
swamped in detail :-). I've actually been using CFC's for a few years now but 
I've been unclear as to if I'm using them in the "right" way. I appreciate that 
these things aren't black and white but I just want to get an opinion on my 
approach.

In my head I know that I should be using CFCs as a tool for common/specific 
tasks but then I look at the example(s) below and think a) it's overkill and 
more code and b) I'm breaking a simple process down into two separate parts 
which might not be needed this way anyway!

No CFC approach:
----------------

<cfif not session.username)>
        <cflocation url="login.cfm" addtoken="no" />
</cfif>

RESULT: Simple, three lines, job done....but no not modular and results in 
duplication.


CFC approach (1):
-----------------

// Get CFCs
UserManager = createObject("component","com.userManager").init();
AppManager = createObject("component","com.appManager").init();

// Check that the username exists in a session  (returns boolean).
userChecker = IWSCFCManager.getUserName();

// No username. Send them to the login page
if(not userChecker){
        appManager.getLogingPage();     
}

RESULT: Process is now in two separate areas so good that it's modular and can 
be cached but it's more external files to deal with.

or I guess all this could be far more generic.

CFC approach (2) - More generic CFC approach:
---------------------------------------------
// Get CFC
AppManager = createObject("component", "com.appManager").init();

// Check that the user exists in the session scope using a generic variable 
checker. This method takes two parameters, the scope and which variable to look 
for. Returns boolean.
userChecker = AppManager.getVariable("session",username);

if(not userChecker){
        // This method does a redirect
        appManager.redirectUser("login.cfm");
}

RESULT: One CFC and could use this for all kinds of things....

.... then again I could just use a structKeyExists :-)... and oh look!!! I'm 
back to another way of coding CFC approach 1 (ARRGGGHHH!!!)

There are many paths but I'm just concerned that I make the wrong one for the 
wrong reasons :-)

@Gerald - Thanks for all those links. OO concepts are something I've never used 
but I've got a good understanding of how it works in principle. I do aim to 
keep everything encaplusated in my CFCS and I'm keen to look at things like 
ColdSpring at some point soon. When I get two "geeky" minutes :-)

Thanks again for the feedback,
James 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:303020
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to