><cfreturn StructDelete(this.Venues, arguments.Venue.getVenueID(), true)>
>
>This line returns "true" if the Venue existed in the collection, "false"
>if it did not.
>
>To add a component you could use StructAppend (which allows you to set
>an overwrite behavior if you like) but I like to do this:
>
><cfif StructKeyExists(this.Venues, arguments.Venue.getVenueID())>
> <cfreturn false>
><cfelse>
> <cfset ArrayAppend(this.Venues, arguments.Venue)>
> <cfreturn true>
></cfif>
>

Matt has pretty much covered the direct thoughts you were looking for, but I
just wanted to chime in regarding your use of cfreturn from your examples.
In my mind (and I'm sure there may be those who disagree), it's not a good
practice to return true/false values from method calls in the manner in
which you have done so. Returning true/false now couples the CFC to your
application code because I'm assuming your calling code is doing something
like:

<cfset myMethodResults = myCFC.myMethod()>

<cfif myMethodResults is true>
  Success
<cfelse>
  Failure
</cfif>

If it's anything like that, then your CFC is now "stuck" having to always
use true/false (or 0/1 or whatever) as a return value. What if your
requirements change which forces you to decide, using your delete example,
that you need to return the remaining structure instead of true/false? Now
all your application code breaks.

My suggestion would be to have a returntype of void and then use
cftry/cfcatch around the method call and trap for known possible exceptions
there. That's a "cleaner" separation of your application code and your CFC.

Of course, as I mentioned, there are those who disagree (this discussion
came up recently on the CFC list), but I've always had better flexibility
when I've used void.

Regards,
Dave.


[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to