The workaround could simply involve a collection of roles that are assigned
to the Vehicle base class during the subclass's initialization.

Base Class Vehicle
        Struct getRoles()
        Void addRole(Sring roleName)
        Boolean hasRole(String roleName)

Then in each derived class, you simply populate this during the init phase:

Truck Extends Vehicle
        init() {
                super.addRole("TowBoats")
                super.addRole("HaulDirt")
                super.addRole("etc")
        }

SportsCar Extends Vehicle
        init() {
                super.addRole("DriveFast")
                super.addRole("ImpressWomen")
                super.addRole("etc")
        }

Then in your final code, you can just check the roles:

<cfset myTruck = createObject("com.Truck")>
<cfif myTruck.hasRole("TowBoats")>
        TowMyBoat
</cfif>

That gives you ultimate flexibility in your derived classes.

Roland

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Barney Boisvert
Sent: Wednesday, April 06, 2005 4:31 PM
To: [email protected]
Subject: Re: [CFCDev] Question on class / subclass

What if you have a subclass of com.truck named com.compacttruck and
need to know if that class can tow a boat?  You'll need to ascend the
object hierarchy and check every level.  Check my UDF from the first
post I made in this thread for an implementation.

Really, this problem pretty much requires interfaces to solve
elegantly, but we don't have them with CFCs.  The vibe I get is that
it's never going to change, which is unfortunate, but such is life. 
You could use synthesized interfaces (an 'implements' attribute in the
CFCOMPONENT tag) to do typechecking, but you'd obviously not get any
of the compile-time benefits.

cheers,
barneyb

On Apr 6, 2005 1:25 PM, Roland Collins <[EMAIL PROTECTED]> wrote:
> > 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>

-- 
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 50 invites.


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