On 7/10/07, Tom Chiverton <[EMAIL PROTECTED]> wrote:
> I *think* CF8's IsInstanceOf() will still throw an error if you've broken the
> contract.
Based on my testing... It will return NO, because it tests - at
runtime - that the contract still holds. However, type="ISomething" on
an argument does not (it only checks the metadata).
Here's an example:
<!--- ITest.cfc --->
<cfinterface>
<cffunction name="foo" returntype="numeric" access="public"
output="false">
<cfargument name="bar" type="string" required="true" />
</cffunction>
</cfinterface>
<!--- Test.cfc --->
<cfcomponent implements="ITest">
<cffunction name="foo" returntype="numeric" access="public"
output="false">
<cfargument name="bar" type="string" required="true" />
<cfreturn len(arguments.bar) />
</cffunction>
</cfcomponent>
<!--- iftest.cfm --->
<cffunction name="test">
<cfargument name="obj" type="ITest" />
<p>Successfully called test with t as an ITest!
<cfoutput>#isInstanceOf(arguments.obj,"ITest")#</cfoutput></p>
</cffunction>
<cfset t = createObject("component","Test") />
<!--- mess with t :) --->
<cfdump label="t-before" var="#t#" />
<cfoutput>
<p>#isInstanceOf(t,"ITest")#</p>
</cfoutput>
<cfset test(t) />
<cfset t.foo = 42 />
<cfdump label="t-after" var="#t#" />
<cfoutput>
<p>#isInstanceOf(t,"ITest")#</p>
</cfoutput>
<cfset test(t) />
We can still call test() after messing with t but isInstanceOf() is no
longer true.
In other words, the only way to be sure the contract is still true is
call isInstanceOf() even in the presence of arguments.
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
CF 8 â Scorpio beta now available,
easily build great internet experiences â Try it now on Labs
http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_adobecf8_beta
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283518
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4