Evik James
Evik James

Reputation: 10483

Do I call the extended CFC or the parent CFC?

I am using ColdFusion 9.1.2.

I have a CFC called orders.cfm. This is the "parent" CFC.

I have another CFC call orderswrapup.cfc. This is an extension of orders.cfc. In orderswrapup.cfc, I have this line at the top:

<cfcomponent extends="orders">

Right now, this doesn't work:

objOrders = createObject("component", "orders");
MyResult = objOrders .someMethodActuallyInOrdersWrapUpCFC();

But this does work:

objOrders = createObject("component", "orderswrapup");
MyResult = objOrders .someMethodActuallyInOrdersWrapUpCFC();

To access the methods in orderswrapup.cfc, can I call the method as though it were "in" orders.cfc or do I need to call it directly? It seems that I should be able to call the parent, not the child.

Upvotes: 0

Views: 391

Answers (2)

Mike Causer
Mike Causer

Reputation: 8314

Extending cfcs is expensive...

If you find yourself needing to go more than 3 levels of extending, you'll start to notice a performance hit.

Upvotes: 0

Brian Hoover
Brian Hoover

Reputation: 7991

orderswrapup has access to all of order's functions, when you create a new orderswrapup object because orderswrapup is a child of order.

You defined orderswrapup.cfc to inherit all of orders.cfc's functions when you defined orderswrapup.cfc as <cfcomponent extends="orders"> This allows you to call any functions in orders.cfc via orderswrapup.cfc as if they were functions inside of orders.cfc. But orders.cfc has no defined relationship with orderswrapup.cfc, so it can't call functions inside of orderswrapup.cfc

Some good writeups - http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=buildingComponents_30.html

Upvotes: 7

Related Questions