Jason,
Try to move as much of the "construction," that is, creating objects
to as few places as possible. Look up the Factory, Abstract Factory,
and Flywheel design patterns for tips here.
One point of these patterns is that constructing objects is often a
bottleneck in the code, so if you can construct a few ahead of time,
you save a little bit of overhead. Another point of these patterns
is that constructing (calling createObject() and init()) often
requires a lot of information - the class path of the object, and
parameters required by init(), etc.
In our shop, we maintain a few server scoped factory objects.
Objects that need to create other objects ask the factories to create
and return them. Now, instead of everyone needing to know where all
of their objects are located and how they are constructed, only a few
factories need to know.
HTH,
Chris
On Jul 19, 2005, at 6:13 AM, [EMAIL PROTECTED] wrote:
I have my objects divided into BO, DAO, Gateway and Manager
Object. Many
of my objects are composed of other objects. For instance I have a
User
object which is composed of a Person object and an array of Company
objects
they sponsor. I'm trying to figure out the best place to load my
Person
object from the database when I instantiate the User.
In my UserManager I do the following
<cffunction name="load" returntype="objects.user" hint="I
load a
user into memory" >
<cfargument name="person_id" type="numeric" hint="I am the
person_id of the user">
<cfset var myUser =
createObject("component","objects.user").init() /> <!--- returns a
blank
User Object --->
<cfset myUser.setPerson_id(arguments.person_id)>
<cfset variables.userDAO.read(myUser) /> <!--- loads
some data
such as their security profile --->
<cfreturn myUser />
</cffunction>
Now, I need to load the person information from the database.
Ultimately
the code that knows how to do this is in the personDAO. I have a
method
that returns a Person object from the person_id in my personManager
(which
is instantiated in the application scope). It could be called with
the
following:
application.personManager.getPersonByPersonId(arguments.person_id)
Should I call this method in the UserManager above, in the
UserDAO's read
method or in the User object's setPerson_id() method?
Should my UserManager, UserDAO or User object know about the
personManager
in the application scope or should I just go ahead and instantiate it
locally in the method or in the variables scope?
Suggestions?
Jason Cronk
[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the
subject of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by
CFXHosting (www.cfxhosting.com).
CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm
An archive of the CFCDev list is available at www.mail-archive.com/
[email protected]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of the
email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).
CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm
An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]