|
|
On Jul 25, 11:39 am, "shorlbeck" <webforumsu...@xxxxxxxxxxxxxx> wrote:
> Thanks for the feedback. Yes, it does help to see that encapsulation isn't
> always the highest priority. Or perhaps I need to expand my definition of
> "encapsulation" to include *groups* of CFC's, which, together, are
> "stand-alone."
One thing you can do is use composition - instantiate another cfc
within the calling cfc and then use the get method throughout the
calling CFC. One nice thing about this approach is that it preserves
encapsulation. Here's an example:
<cfcomponent displayname="SalesOrderController"
hint="SalesOrderController" extends="salesOrderBase" output="false">
<cffunction name="init" displayname="init" hint="init"
access="public" output="false" returntype="SalesOrderController">
<cfreturn this />
</cffunction>
<cffunction name="getSalesOrderUI" access="public" output="false"
returntype="any">
<cfif not structKeyExists(variables,"salesOrder")>
<cfset setSalesOrderUI() />
</cfif>
<cfreturn variables.salesOrder />
</cffunction>
<cffunction name="setSalesOrderUI" access="public" output="false"
returntype="void">
<cfset variables.salesOrder = CreateObject("component",
"activeSOUI") />
<cfset variables.salesOrder.init() />
</cffunction>
<!---
other functions go in here
--->
</cfcomponent>
Then all I have to do in the rest of the CFC when I need to refer to
the sales order UI functions, is to call getSalesOrderUI() and the
function name, getSalesOrderUI().getCart() for instance. So this
allows for any external function to be used within the CFC and stil
preserve encapsulation.
regards,
larry
|
|