First off, the Gateway is designed to provide "aggregated access" to your data as opposed to "per object access" to your data. It addresses performance because you typically don't want to create objects for each row of your result set. By looping over your result set from the gateway and creating object instances your negating that so that's not recommended.
Number 2, you don't want your business objects to know about persistance. So your article shouldn't have an instance of articleDAO Read http://livedocs.macromedia.com/wtg/public/machiidevguide/models.html for more on this a typical design with BO,gateway and DAO. As for only having 1 instance of DAO, you'll typically have a "manager" object in the mix that coordinates your BO and DAO. In Mach-II this is a Listener. In the contructor (configure method), is where the reference to the DAO is and there is only one created since the Listener is only created once and stored in application scope. Does that help? -Phil On Tue, 25 Jan 2005 18:10:22 -0200, Marcantonio Silva <[EMAIL PROTECTED]> wrote: > > > Hello, > > This seems to be a design problem to me (but could also be ignorance) and > maybe somone can see a better way: > > I'm working with a DAO and a Gateway for, lets say, multiple article > retrieve, I have a DAOFactory that instantiates the DAO depending on the > type (eg: MSSQL, ORA etc). > I want a struct of article objects, so what I do is send a getArticles() to > the gateway, it runs a query, loops over it and creates one object for each > row, storing them in the struct: > > [articleGateway.cfc getArticles()]: > cfset stArticles = structNew() > [loop over articlesGateway] > stArticles[key] = > createObject("component","article").init(stConfig).getArticle(query values) > [/end loop] > return stArticles > > > Inside the bean I init the DAO from the factory: > > [article.cfc init()]: > cfset variables.articleDAO = > createObject("component","model.factory.DAOFactory").init(arguments.stConfig).getDAOFactory(factoryType:arguments.stConfig.dbtype).getArticleDAO(arguments.stConfig) > > > First I had this in the constructor, but then I decided to move the > "stConfig" from the constructor to the init, in order to avoid > duplication of the XML functions that are parsed everytime I instatiated the > config.cfc.init() method > (actually, I got it under the application scope, but didn't feel right to > have dozens of calls to the method, so I decided moving it with every call > to init methods on my app, like Mach-ii dos with the appManager). > > The problem is that everytime an articleBean is instantiated it has to call > the DAOFactory, and eventually this will start decreasing performance at > runtime. > So if I have to instantiate, lets say, 20 articles, I would have to init the > DAOFactory 20 times, it dosen't seem right. > > To resolve the problem, I could instantiate the DAO once, and send it to the > init() method of the article everytime, but this seems an overkill: > (eg: stArticles[key] = > createObject("component","article").init(stConfig,articleDAO).getArticle(query > values) > > I would also have the article bean init() depending on receive the DAO, > which I don't want, since sometimes I want to create a blank article, > or even an article populated by a form, and I dont need a DAO for doing > this. > > What I could do, if I could use my old CF skills woul be: > > > [article.cfc init()]: > <cfif NOT isDefined("request.articleDAO")> > <cfset request.articleDAO = > createObject("component","model.factory.DAOFactory"). ... /> > </cfif> > <cfset variables.articleDAO = request.articleDAO > > > > This way I wouldn't have 20 instantiations of the DAO, but it doesn't seem > right too ... I shouldn't be allowd to use the request scope, should I ? > > I guess this could be done with a singleton for managing the DAOFactory, and > instead of creating it everytime I could get it from the singleton, but is > this right design ? > Is there any better way of doing this ? > > []s > > > > Marcantonio Silva > Product Development - ContentObjects > [EMAIL PROTECTED] > www.contentobjects.com > Phone: +55 11 3055.2004 > Mobile: +55 11 7732.4907 ---------------------------------------------------------- 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]
