Jason,

I think you've got things upsidedown. Let me start by saying i had things
upsidedown for awhile too, so i really understand.

My understanding of the situation is that generally speaking, you don't
instantiate parent classes. I know it can sound weird, but in OO, parents
don't know what kind of children they've got.

You wanna design your model so that the common stuff that all trucks, sports
cars and suv's share is in Car, and instantiate only Truck, SportsCar and
SUV.

If that doesn't work for what you wanna do, then you're probably looking at
composition, not inheritance.

For me, the key to getting this was that you abstract common functionality
to the parent, rather than duplicating code in all the children.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of [EMAIL PROTECTED]
Sent: Wednesday, April 06, 2005 6:32 PM
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