Nathan, thanks for the reply.

I should have mentioned that this is the Application.cfc that I'm
buildling.  That is why I'm using the CGI scope in the constructor.

This is sort of a follow-up to a post I had a few weeks ago.  This code
will be placed in the constructor of the Application.cfc to redirect a
browser to a secured connection.  It was determined that the
most-logical place was the constructor just so no Application.cfc
methods would have to fire before the redirect took place.

I am fine with that logic.

However, it seems like I am making my code too-complex for this simple
task of redirecting a browser.  On the other hand, I would still like to
adhere to best practices.

After looking at my code, again, I noticed that my "redirectBrowser" is
doing two things:  Determining if the browser should be redirected and
then doing the actual redirect.

If I were to refactor this code, I should have a method to determine if
the browser should be redirected, then, if so, call the
"redirectBrowser" method.

But, then I think that I'm making it too complex for the deed.

Thanks,
Mike

-----Original Message-----
From: Nathan Strutz [mailto:str...@gmail.com] 
Sent: Tuesday, July 21, 2009 2:38 PM
To: cf-talk
Subject: Re: Function Encapsulation Gone Too Far? - Opinions


It's hard to say if you're really overdoing it.

In one sense, the component is pretty well encapsulated.

Accessing the cgi scope just in the constructor is fair enough, though
for the true purists, you could move that out, and for the OO realists,
you could just put cgi references anywhere.

Also the use of the constructor, while not a no-no, is usually
overlooked in support of an init method. I know I always look first for
an init method well before looking for constructor code. Still, it's
perfectly fine.

If you think this is an area of your app that will change, then by all
means, encapsulate it, give it its own object etc.

However...

It's like 3 lines of code you could drop in your onRequestStart method.
You'd eliminate an entire object creation, 2 cffunctions, 20+ lines of
code:

<cfif cgi.server_name neq listFirst(arguments.hostName, ".") & ".
evansville.edu" or cgi.https neq "on">
   <cflocation "https://"; & listFirst(arguments.hostName, ".") & ".
evansville.edu/" />
</cfif>


But if you are going to need to overwrite that functionality in certain
cases or add complexity later on, you might as well separate it out at
least a little.


nathan strutz
[Blog and Family @ http://www.dopefly.com/] [AZCFUG Manager @
http://www.azcfug.org/] [Twitter @nathanstrutz]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:324771
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