I sort of agree with Brian but found I rarely touch DAO objects once they are in place but often have to add stuff to gateway objects (new report or new complicated SELECT query the dba wants for performance reasons).
So following the 'encapsulate what varies' idea I keep them separate. Alan ________________________________________ From: [email protected] [EMAIL PROTECTED] On Behalf Of Brian Kotek [EMAIL PROTECTED] Sent: 20 June 2008 22:06 To: [email protected] Subject: [CFCDEV] Re: Doubts about Best Practices On Fri, Jun 20, 2008 at 2:49 PM, Ronan Lucio <[EMAIL PROTECTED]> wrote: Hi, I have two doubts hitting my mind: 1) What is the best way to populate foreign keys into a bean? Supposing I have a class Product. Each product has a Category. What is the right way: beanProduct = serviceProduct.getBean(); beanProduct.setName( "It's name" ); beanProduct.setCategory( 1 ); or beanCategory = serviceCategory.getBean( 1 ); beanProduct = serviceProduct.getBean(); beanProduct.setName( "It's name" ); beanProduct.setCategory( beanCatebory ); or neither? I would create a Factory that would create the product, populate it with any passed data, as well as creating and populating any composite objects. This way the logic for populating the object and resolving its dependencies is encapsulated within the factory. 2) In CF community we use to talk about DAOs and Gateways but it doesn't seem a widely used pattern. What is the best usage? Have just one DAO as Row Data Gateway and Table Data Gateway or use DAO as RDG and Gateways as TDG? I'd actually say the opposite: not only is it widely used, it may arguably be over-used. It's become somewhat common to see every single table in a database have corresponding Gateway objects and DAO objects. I personally don't separate single-row persistence behavior in a DAO and aggregate behavior in a Gateway, I just have a Gateway and it does both. I also don't necessarily have separate Gateways for every single table, but rather group the behavior logically. So I may have forum, thread, and message tables in the database, but I may group the SQL for these together into a ForumGateway. In other words, just because the tables are there doesn't mean there must be separate DAO and Gateways for every one (nor Services for that matter). Hope that helps? regards, Brian Thanks, Ronan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CFCDev" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfcdev?hl=en -~----------~----~----~----~------~----~------~--~---
