The Dopefly Tech Blog

« The Dopefly Tech Blog Main page

Fun with Functions and CFCs IV - Public Method, Different from the Private Method

posted under category: ColdFusion on December 13, 2007 by Nathan

Here's an interesting idea. Probably not a good one, but check it out. What if external calls to a CFC method execute something different than when you call that method from within the CFC? It's easy. Here's the code:


  <cffunction name="init" access="public">
    <cfreturn this>

  <cffunction name="privateMethod" access="private">
    <cfreturn "This is a Private Method!">

  <cffunction name="publicMethod" access="public">
    <cfreturn "This is a Public Method!">

  <cfset this.genericMethod = publicMethod />
  <cfset variables.genericMethod = privateMethod />


Now private calls to genericMethod() will give you the private method message, and public calls to myCFC.genericMethod() will return the public method message.

I honestly can not think of a use case for this one. Got any? leave a comment.

Nathan is a software developer at The Boeing Company in Charleston, SC. He is essentially a big programming nerd. Really, you could say that makes him a nerd among nerds. Aside from making software for the web, he plays with tech toys and likes to think about programming's big picture while speaking at conferences and generally impressing people with massive nerdiness and straight-faced sarcastic humor. Nathan got his programming start writing batch files in DOS. It should go without saying, but these thought and opinions have nothing to do with Boeing in any way.
This blog is also available as an RSS 2.0 feed. Click your heels together and click here to contact Nathan.