Search Blog

Recent Comments
Re: Stats plugin ported to Model-Glue (by J.mihai at 12/14 8:52 AM)
Re: CFC DAO Generator (by rui at 7/04 5:42 AM)
Re: Updates to the DAO, Bean and Gateway generator (by rui at 7/04 4:49 AM)
Re: CFC DAO Generator (by fwscott at 6/22 7:03 PM)
Re: CFC DAO Generator (by dan at 6/22 12:38 PM)
Re: Trip to Thailand (by fwscott at 3/27 2:10 AM)
Re: CFC DAO Generator (by fwscott at 3/27 2:03 AM)
Re: CFC DAO Generator (by Garry Harstad at 3/26 12:30 PM)
Re: Trip to Thailand (by Niqui Merret at 3/23 4:51 PM)
Re: Adding a blogger ping utility to BlogCFM (by fwscott at 2/20 9:01 PM)
Categories
Annoucements (1 entries)
BlogCFM (3 entries)
CFC Generator (5 entries)
Coldfusion (11 entries)
Fusebox (2 entries)
Greasemonkey (1 entries)
Misc (3 entries)
Archives
November 2005 (2 entries)
October 2005 (1 entries)
August 2005 (1 entries)
July 2005 (4 entries)
June 2005 (5 entries)
May 2005 (7 entries)

Powered by
BlogCFM v1.01

November 2005
CF_Implements
Post a Comment
I got bored last night and decided I would try to come up with a way to have an "Implements" keyword in ColdFusion.

The download contains four files
  1. implements.cfm - If you want to use the custom tag version, copy this to your CustomTags directory.
  2. implements.cfc
  3. iComponentCache.cfc - a sample interface
  4. ComponentCache.cfc - a sample class using the "Implements" keyword.
Useage:
For the Custom Tag, at the very top of your CFC put a
<cf_implements interfaces="full.path.to.interface1,full.path.to.interface2,etc,etc" />

 It will throw an error if the class does not implement all the methods in the interfaces provided.
Example:
<cfcomponent>
   <cf_implements interfaces="iPerson" />
   <cffunction name="test" ..........
......
.....
</cfcomponent>


For the implements.cfc, You can use the object's init method to check the interface for an object anywhere.  To force a cfc to implement something, use
<cfset createObject("component","path.to.implements.cfc").init(this,"path.to.interface1,path.to.interface2") />

Example:
<cfcomponent>
   <cfset createObject("component","com.implements").init(this,"com.iPerson") />
   <cffunction name="test" ..........
......
.....
</cfcomponent>

If you want to make sure an instance passed to a function uses a certain interface, replace "this" with "arguments.whatevertheinstancevariableis".
Example:
<cffunction name="savePerson" access="public" output="false">
   <cfargument name="thePerson" type="any" required="true" hint="Must implement iPerson" />
   <cfset createObject("component","com.implements").init(arguments.thePerson,"com.iPerson") />
   .....
....
</cffunction>


There are a couple other things.
  1. To set the custom tag to "production" mode.  put <cf_implements mode="production" /> in your application.cfc/.cfm
  2. To set the implements.cfc to "production" mode, you must pass the argument "mode" with the value of "production" to the init method.
  3. You can also pass in your own CacheManager to the implements.cfc, the passed in CacheManager must implement iComponentManager.
I havent tested this in a production environment, and hardly tested in a testing environment... but would like some feedback before I try to improve this.

Can download it here

Enjoy
Posted by fwscott at 5:07 PM | Comments (0)
 
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

No comments found.

Name:   Required
Email:   Required your email address will not be publicly displayed.

Want to receive notifications when new comments are added? Login/Register for an account.

Anti-spam key

Type in the text that you see in the above image:

Your comment:

Sorry, no HTML allowed!