I asked this previous question regarding multiple inheritance in coldfusion cfcs. Now, I have a question of whether this would work to mimic multiple inheritance in cfcs and what the drawbacks might be.
Suppose I have these 4 classes: Animal, Horse, Bird, Pegasus.
- Horse and Bird are subclasses of Animal.
- Pegasus is a subclass of Horse.
- However, Pegasus flies the same way that an instance of the Bird Class does.
Instead of defining fly() identically twice in the Bird class and the Pegasus class, can I define it in a separate file and include it in the cfc of Pegasus and Bird? Are there any drawbacks to doing this?
horse.cfc
<cfcomponent extends="animal">
<!--- misc functions run, eat, whinny... --->
</cfcomponent>
bird.cfc
<cfcomponent extends="animal">
<cfinclude template="flier.cfm">
<!--- misc functions hop, eat, chirp... --->
</cfcomponent>
pegasus.cfc
<cfcomponent extends="horse">
<cfinclude template="flier.cfm">
</cfcomponent>
flier.cfm
<cffunction name="fly">
<!--- flying action --->
</cffunction>
I have tried this code and at first glance, it seems to work for what I'm trying to accomplish, but since it was not a mentioned solution to my previous question about multiple inheritance in CFCs, I would like some feedback as to whether this would be a good way to go or not.