> Instead of asking the car what type of car it is, why don't you just
>ask it whether it can tow boats?
>
><cfif myCar.canTowBoats()>

The only problem with this is flexibility.  For each role that you then want
your vehicles to maintain, you have to add a property.

As far as runtime determination of class name - that's easy!  No need to
store it anywhere:

<cfif GetMetaData(myVehicle).Name is "com.truck">
        Tow my boat!
</cfif>



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Patrick McElhaney
Sent: Wednesday, April 06, 2005 3:29 PM
To: [email protected]
Subject: Re: [CFCDev] Question on class / subclass

On Apr 6, 2005 12:32 PM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> 
> <cfset myCar = createObject("component","com.car").init()>
> <cfset carDAO.read(myCar,form.vin_number)>
> <cfif myCar.getType() is "truck">
>       <cfset  myCar.towBoat()>
> <cfelse>
>       Sorry, you can't tow a boat with your car
> </cfif>

Instead of asking the car what type of car it is, why don't you just
ask it whether it can tow boats?

<cfif myCar.canTowBoats()>

You can have your SUV and Truck CFCs always return true, and your
SportsCar CFC always return false. Later, if you add a Motorcycle CFC
and a Sedan CFC you don't need to change the code that works with
cars.

The code above could be rewritten like so.

<cfset carDAO.read(myCar,form.vin_number)>
<cfif myCar.canTowBoats()>
      <cfset  myCar.towBoat()>
<cfelse>
      Sorry, you can't tow a boat with your car
</cfif>

Patrick

-- 
Patrick McElhaney
704.560.9117
http://pmcelhaney.weblogs.us


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of the
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]





----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]


Reply via email to