That's exactly what interfaces provide, but packaged up in a fairly
inelegant way (at least to my eye).  My main gripe?  The fact that the
roles are assigned programatically, rather than declaratively.  You
also can't assign behaviour to a role, since a role is just a string. 
With an interface you can include behavior (and even state, for that
matter).

I still think the custom 'implements' attribute on CFCOMPONENT, and
then using a modified version of my instanceOf function is a cleaner
way to go, because it keeps everything declarative.

cheers,
barneyb

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

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


Reply via email to