2

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?

Leigh
  • 28,765
  • 10
  • 55
  • 103
user3733648
  • 1,323
  • 1
  • 10
  • 25
  • That's a design pattern called [Mixin](https://en.wikipedia.org/wiki/Mixin): "In object-oriented programming languages, a mixin is a class that contains methods for use by other classes without having to be the parent class of those other classes. [...] Mixins are sometimes described as being "included" rather than "inherited"." As far as scoping, and functions within the included file should still be properly var-scoped, and the included functions have access to the object they are included in. – beloitdavisja May 23 '17 at 12:14

1 Answers1

4

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.

Shawn
  • 4,758
  • 1
  • 20
  • 29
  • I guess one other thing is that you can directly include multiple files, but you can't directly extend multiple files. – Shawn May 23 '17 at 15:41