Hi Magnus, On the scope issue, use variables scope for any variable you need available to all functions in the cfc. Use the local scope "var" on any variable local to the function. It's important to make sure to var scope all your local function variables, including things like query names and indexes in loops.
On the relationship between objects, in my experience, you can either get clear or get confused thinking about what has what. "Has" and "Is" are good tests to use, but they aren't always good determiners. You can get caught in circles trying to use them as determiners. (Hmmm, a product has a name ... do i need a Name object?) A company has products and customers and a customer has orders and an order has payments, but that doesn't necessarily mean you should compose all those in your model one inside the next. I *think* it depends more on what specific functionality the application is modeling. In other words, what does the application need to do each task it needs to do? Or which of the objects need to work together to get a particular task done. You may also find that you can bring objects together to get a task done in a manager of some sort. I'm just playing with ideas, so don't take this as well thought out, but maybe you could use an OrderManager whose responsibility it is to process orders, kind of like a sales clerk. and you might do something like pass Order, Customer, and Product into OrderManager. Or Pass Product and Customer in and create the Order within OrderManager. In any case, if you did use an OrderManager, it could also create the DAO's when needed and persist the order to your database. If you think about it, in a real shop, you DO need someone at the cash register to process orders. An Order itself couldn't be responsible, nor could a Customer or a Product. So my sense is you're missing at least one player in your model at this point ... and maybe someone with more experience with this scenario might chime in how they solved it. :) nando -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Magnus Wege Sent: Saturday, November 13, 2004 4:03 PM To: [EMAIL PROTECTED] Subject: AW: [CFCDev] Problems with inheritance and DAO Objects Hi Nando, thanks for the recent replies, Let me figure it out: I have the following CFCs in my Project Order.cfc OrderDAO.cfc OrderPayments.cfc OrderPaymentsDAO.cfc Customer.cfc CustomerDAO.cfc Product.cfc ProductDAO.cfc Company.cfc CompanyDAO.cfc With the following relations: 1 Order has 1 Customer 1 Customer has n Orders 1 Order has n Order Payments 1 Payment belongs to 1 Order 1 Order belongs to 1 Company 1 Company has got n Orders 1 Order has 1 Product 1 Product belongs to n Orders Well the question is how do I implement these aggregations correctly? @Nando: your last email was of great help. Thank you for this study stuff. I will try to apply your code to my DAO-Design. I think I just walked the wrong way (instantiating the DAOObject in the mother class Order.cfc). One Question on your properties of the OrderDAO.cfc: I thought properties should be in the this-scope? May be that�s why I cannot access the properties of the Order.cfc because they are all in this-scope? Greetings Magnus -----Urspr�ngliche Nachricht----- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Nando Gesendet: Samstag, 13. November 2004 15:39 An: [EMAIL PROTECTED] Betreff: RE: [CFCDev] Problems with inheritance and DAO Objects Oh, one more thing ... i have a suspicion that you might need to adjust the relationship between the parent and child ... i needed to do this a few weeks ago and your situation sounds similar. Maybe someone more experienced will chime in, and maybe you could post the objects in question and how you have them currently modeled, and we see what happens. -----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] ---------------------------------------------------------- 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]
