well, i guess that depends. you could explicitly set a property e.g.
"cartype" in the init(),
or slightly messier, you could use getmetadata(mycar)....

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of [EMAIL PROTECTED]
Sent: 06 April 2005 17:32
To: [email protected]
Subject: [CFCDev] Question on class / subclass






Hi,

This is probably a simple question but I haven't seen it explicitly
illustrated anywhere.


   Lets say I have the classic CAR class and subclasses SportsCar, Truck
and SUV.  I get an instance myCAR and I need to determine if myCAR is a
SportsCar, Truck or SUV.  Would I call a method in CAR such as
myCar.gettype()?  Or in this case is being a SportsCar, Truck or SUV just
an attribute of CAR not a subclass (where I would have sportscar.cfc,
truck,cfc, suv.cfc)?  I'd prefer it to be a subclass since those subclasses
have different methods like Truck.towBoat().  But I don't know if I can tow
boat with myCAR because I don't know if myCAR is a Truck.

Some code to illustrate what I'm looking for....


<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>


Obviously a big fallacy here would be that myCar is a CAR object and
probably would have to be recast as a Truck object for me to call
myCar.towBoat().  Something like
<cfset myCar = createObject("component","com.truck").init()>
<cfset truckDAO.read(myCar,form.vin_number)>
within the cfif tag.


Am I missing some fundamental property here?  How do I refer to a generic
unknown car and yet have subclasses of cars that behave differently?


Jason Cronk
[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]





----------------------------------------------------------
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