|
Your code makes sense. Here's the
reason why I did not check to see if the argument of "animal" exists as in
<arguments.animal.getFoodType() ...>, I consider getFoodType() as an
"attribute" to "animal" in the sense that it describes "animal" or a property of
"animal", so, also a method. Hence, an analog would be like
this,
house X has [1,2,3] rooms,
now, someone said if X[1].color = red
...
I naturally assumed house X exists in the first
place.
In the OO world, is
it different?
Thanks.
DL
----- Original Message -----
Sent: Wednesday, October 13, 2004 5:30
PM
Subject: Re: [CFCDev] Coding
> I would write the following block of code (from
the whole thing) > <cfcase
value="dangerous"> >
<cfif arguments.animal.getFoodType() is
"meat"> >
<cfset lockAnimal(arguments.animal)
/> >
<cfset arguments.animal.eat("meat pellets")
/> >
<cfset unlockAnimal(arguments.animal)
/> > <cfelseif
arguments.animal.getFoodType() is
"veggie"> >
<cfset lockAnimal(arguments.animal)
/> >
<cfset arguments.animal.eat("veggie pellets")
/> >
<cfset unlockAnimal(arguments.animal)
/> >
</cfif> > </cfcase> > >
as > <cfcase value="dangerous"> > <cfset
lockAnimal(arguments.animal) /> > <cfif
arguments.animal.getFoodType() is "meat"> > <cfset
arguments.animal.eat("meat pellets") /> > <cfelseif
arguments.animal.getFoodType() is "veggie"> > <cfset
arguments.animal.eat("veggie pellets") /> > </cfif> >
<cfset unlockAnimal(arguments.animal) /> >
</cfcase>
Sounds reasonable. But from this sample I don't
know whether lockAnimal() and unlockAnimal() and getFoodType() might cause
some sort of deadlock. If I knew it couldn't, I might code it your way. If
it could potentailly, or if I didn't know, or if I didn't control those
functions, I might code it as:
<cfcase
value="dangerous"> <cfset FoodPellets = "undefined pellets"
/> <cfif arguments.animal.getFoodType() is "meat"> <cfset
FoodPellets = "meat pellets" /> <cfelseif
arguments.animal.getFoodType() is "veggie"> <cfset FoodPellets =
"veggie pellets" /> </cfif> <cfset
lockAnimal(arguments.animal) /> <cfset
arguments.animal.eat(FoodPellets) /> <cfset
unlockAnimal(arguments.animal) /> </cfcase>
...or, if the
choice is only meat or veggie:
<cfcase
value="dangerous"> <cfif arguments.animal.getFoodType() is
"meat"> <cfset FoodPellets = "meat pellets" /> <cfelse
arguments.animal.getFoodType() is "veggie"> <cfset FoodPellets =
"veggie pellets" /> </cfif> <cfset
lockAnimal(arguments.animal) /> <cfset
arguments.animal.eat(FoodPellets) /> <cfset
unlockAnimal(arguments.animal) /> </cfcase>
--
Ben Curtis WebSciences International http://www.websciences.org/ v: (310)
478-6648 f: (310)
235-2067
---------------------------------------------------------- You
are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words
'unsubscribe cfcdev' in the message of the email.
CFCDev is run by
CFCZone (www.cfczone.org) and
supported by Mindtool, Corporation (www.mindtool.com).
An archive of the
CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
|