Here's the situation. I've got my application working fairly well. Now i'm trying to
refactor / improve the way it's working, now that i've had a few solid months of
working with CFC's
The main objects
Site: instance cached in application scope, stores application wide data like
navigation, generates breadcrumbs from navigation, etc
Page: uses cached instance data in Site to generate page specific navigation,
breadcrumb, and contentProperties for that page
ContentItem: uses the contentProperties from Page to determine which specific
ContentObject to instantiate (Text, Image, etc), and whether the ContentObject should
display itself (allowing user choice of content types) or not (and then it only
returns a recordset to the calling template, and the display is handled there.)
I'm trying to figure out the best way to make the instance data of Site available to
Page and the instance data of Page available to ContentItem, preferably from within
the objects. It *seems* like the Machii framework functions in this way, but i don't
quite know if that's true. I've stared at the code but didn't get it.
Another version of the question is this: Site is a container of PageS, and Page is a
container of ContentItemS - but to make composition work in the sense that each of
these depends on it's parent container, it seems the only way is to pass an instance
of Site inside Page and to pass an instance of Page inside ContentItem - and that
seems backwards to me.
So i tried instantiating Page from within Site:
<cffunction name="setPageObj" access="public" returntype="void" output="no">
<cfset variables.thisPage = createObject('component','Page2')>
</cffunction>
<cffunction name="getPageObj" access="public" returntype="any" output="no">
<cfreturn variables.thisPage>
</cffunction>
(It choked on the returntype, so i left it any just to get it to work)
Then i managed to get it working like so:
<cfset thisPage = application.thisSite.getPageObj() />
<cfset thisPage.init(pageState) />
But it doesn't (seem to) help "compose" anything. I can't access the functions in Site
this way (or can i??? I've tried this several times, thinking it should work somehow).
I'm wondering how to use a group of objects that are instantiated by other objects or
each other - i don't understand that yet. How are they able to comunicate with each
other, how to bridge the encapsulatory divide? :)
As it now stands, i'm breaking encapsulation in Page by accessing thisSite via the
application scope (or am I? I'm not sure):
<cffunction name="generateContentArray" access="private" returntype="void"
output="no">
<cfset var thisCAContent = ""/>
<cfset var arrContent = ArrayNew(1) />
<cfset var allContent = application.thisSite.getAllContent() />
....
<cfset variables.arrContent = arrContent />
</cffunction>
And passing Page into ContentItem:
<cffunction name="init" access="public" returntype="Content">
<cfargument name="thisPage" type="Page" required="yes">
<cfset variables.thisPage = arguments.thisPage />
<cfreturn this />
</cffunction>
And putting thisPage in session scope when i need to persist the pageProperties during
admin operations.
And it all works, but i'm pretty sure there's a better way and it seems like it's time
to ask for advice. How to get these fellows to collaborate? Or am i doing this "right"
???
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]