coldfusioncoldfusion-9cfwheels

Difference between including a template in cfc and extending it


I thought that one should extend .cfc components, but I am reading the cfwheels framework source where I see something like this:

<cfcomponent output="false" displayName="Controller">
    <cfinclude template="../wheels/controller.cfm">
</cfcomponent>

What is the difference between extending the component and including a template as is done above?

Also, are there any scoping issues that I should keep in mind?


Solution

  • I think it would totally depend on what was in the included/extended file. One reason this may have been this way is because you can't extend a CFC below the current level (can't do extend="../wheels/controller.cfm"), so this is essentially just "proxying" the file directly. To extend the "../wheels/controller.cfm, you would first have to actually proxy the file by creating a new cfc in the local directory (proxy.cfc) and cfincluding the controller.cfm file in there. Then extend proxy.cfc.

    Functionally, they are pretty similar. Conceptually, I would say that an included cfm file may have specific functionality that solves an individual issue whereas an extended cfc file should probably be a wholly functioning piece all on it's own that happens to hold a behavior that the extending class needs.