Magnus,

Instead of instantiating OrderDAO within Order, consider passing Order into
OrderDAO whenever you need to. I always instantiate the DAO each time i need
it. Here's an example, assuming Order is in session scope:

from somewhere in your app:

<cfset createObject('component','OrderDAO').init(
                                session.Order).read(idOrder) />

from OrderDAO

        <cffunction name="init" access="public" returntype="OrderDAO"
output="false">
                <cfargument name="Order" type="Order" required="Yes" />
                <cfset variables.Order = arguments.Order />
                <cfset variables.dsn = arguments.dsn />
                <cfreturn this />
        </cffunction>

.....

        <cffunction name="read" access="public" returntype="VOID" 
output="false">
                <cfargument name="idOrder" type="numeric" required="yes" />

                <cfset var qRead = "" />

                <cfquery name="qRead" datasource="#variables.dsn#">
                        SELECT *
                        FROM tblOrder
                        WHERE idOrder = <cfqueryparam cfsqltype="cf_sql_integer"
value="#arguments.idOrder#" />
                </cfquery>

                <cfif qRead.RecordCount GT 0>
                        <cfset 
variables.Order.setInstanceFromStruct(queryRowToStruct(qRead)) />
                </cfif>
        </cffunction>

.....

        <cffunction name="queryRowToStruct" access="private" returntype="struct"
                        hint="I return a structure from a queryRow passed into 
me."
output="false">
                <cfargument name="query" required="Yes" type="query" />
                <cfargument name="row" type="numeric" default="1" />
                <cfset var ii=1 />
                <cfset var cols = listToArray(query.columnList) />
                <cfset var structReturn = StructNew() />

                <cfscript>
                        for(ii = 1; ii lte arraylen(cols); ii = ii + 1){
                                structReturn[cols[ii]] = 
query[cols[ii]][arguments.row];
                        }
                </cfscript>

                <cfreturn structReturn />
        </cffunction>

If you like, post a shortened list of your Order properties and i'll post
back a BO / DAO pair showing you how i'm doing this for you to study and
adapt. I have to go out for a few hours now, so i could only do this a
little later.

ciao,
Nando

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Magnus Wege
Sent: Saturday, November 13, 2004 2:37 PM
To: [EMAIL PROTECTED]
Subject: [CFCDev] Problems with inheritance and DAO Objects


Hi everyone,

I am quite new in applying OOD/P to CF via implementing cfcs. So here is my
problem:

I have a CFC called Order.cfc.
Within this CFC I create several DAO Objects (e.g. for related customers
instantiating the CustomerDAO.cfc)
So far so good.
Now I want all the SQL stuff from the Order.cfc out of it and put it to
OrderDAO.cfc.
So I created a new property of the Order.cfc by instantiating the
OrderDAO.cfc through the init-Method of the Order.cfc:
<cfset this.oOrderDAO  = createObject("component","OrderDAO").init() />

By the getter-Method in the Order.cfc I can get access to these DAO-Objects.
        <cffunction name="getOrderDAO" output="false" returntype="struct">
                <cfreturn this.oOrderDAO/>
        </cffunction>

Now I want to set my properties (all the variables in the this-scope) via
calling the method selectOrders() and calling the mother's method in
Order.cfc named setOrdersByStruct(queryResult) in the OrderDAO.cfc using
super.setVertragByStruct()

        <cffunction access="public" name="selectVertrag" output="true">
                <cfargument name="iVertragID" type="numeric"
required="true"/>
                        <cfquery name="variables.qSelectVertrag"
                                        datasource="#this.sDsn#">
                        SELECT
                                *
                        FROM
                                Order
                        WHERE
                                pk_Order = #val(arguments.iOrderID)#
                        </cfquery>
                        <cfset
super.setVertragByStruct(variables.qSelectVertrag, "query")/>

        </cffunction>

An other issue is that I need to get the properties (through the
getter-Methods) of the mother's cfc in the child CFC. As I know I cannot get
direct access to the this-scope in the mother CFC, so the getter-Method
fails.

How can I do apply the DAO-Pattern correctly? I heard something of a
Transfer Object that may be the golden key to solve this problem. Can
anybody explain this to me please?

Great thanks in advance for any help. I am looking forward to your replies.


Magnus Wege

____________________________________________
web-shuttle AG | Tel +49 89 130 145-0
Wilhelm-Hale-Str. 53 | Fax +49 89 130 145-10
D-80639 Munich | Germany



----------------------------------------------------------
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
[EMAIL PROTECTED]


----------------------------------------------------------
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 
[EMAIL PROTECTED]

Reply via email to