Magnus, It's highly recommended not to use the this scope within object oriented CFC's because it breaks the encapsulation of your object. You can overwrite the variables in you cfc from the calling page using "this", if i'm not mistaken, either intentionally or by mistake. I read about it in Hal Helms book on CFC's and here on this list, and haven't messed with it since.
Yes, "variables" is global to the component but is isolated from the calling page, so there is no danger that something will get overwritten in your object. And i might add that many people think it's best practice to scope every variable in your cfc's - either variables.myVariable, arguments.myVariable, or declare it local with var at the top of the function - var myVariable - and continue to use it locally, without a scope declaration, in your function. If you don't scope your variables, you can wind up having something global to the cfc when you think it's local (by not using var) - which can create some elusive bugs. To me, the difference between object relationships and database design relationships is that in an object model, something happens. The database is static, but the objects are active, they come together to complete a task. So the question to me is, do Order and OrderPayments need to work together in your app to complete a task? What is it? Maybe the only task is RemindCustomerToPay, and maybe you'd need Customer and OrderPayment and Order to work together to do it. Maybe the task is CheckIfFullyPaid, and you'd only need to bring OrderPayment and Order together. I've found you often need additional objects to get things done, ones that aren't represented in any way in your database, but they probably DO exist in the "world" you're trying to model in one way or another. Getting things done is very different from storing data. You need to assemble a team, assign responsibilities, try it out and fill in the gaps, either by assigning more responsibilities, or rearraging the assignments, or by bringing in more objects to your team. So to me, you probably need to step back and think about the business process you are attempting to model. What elements, what players, what objects do you need to complete the process or processes. Storing the data is perhaps only a minor part of the process as a whole. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Saturday, November 13, 2004 9:05 PM To: [EMAIL PROTECTED] Subject: AW: [CFCDev] Problems with inheritance and DAO Objects hi nando, so i think variables in the variables-scope are global variables to the component. But as the this-scoped variables are properties of the component they are also global variables, arent they? I guess (but not tried out so far) that this-scoped variables are only accessible through the getter-methods. Regarding the aggregation issue I think it is of course a matter of the business model. For me it is just a little bit difficult to think in OOP instead of relational databases. Going further the OOP idea I have an object Order with several properties. Lets have just a look on the 1:m relation between Order and OrderPayments. How would you design this in CFCs? Can anybody give me an example on that? Magnus --- Urspr�ngliche Nachricht --- Datum: 13.11.2004 20:00 Von: [EMAIL PROTECTED] An: <[EMAIL PROTECTED]> Betreff: RE: [CFCDev] Problems with inheritance and DAO Objects > 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] > ---------------------------------------------------------- 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]
