Aaron,

Functionally, there really is no difference between using the object factory
the way we did and instantiating an object in the application scope as you
are suggesting.

When a variable, or object, is passed 'by reference', it simply means that a
new instance of the variable or object is not created, however a 'pointer'
is used to 'point' to the original variable.  Here is a basic code snippet
that might help clarify.

<cfset var1 = structNew() />
<cfset var1.myName = 'Scott' />
<cfset var2 = var1 />
<cfset var2.myName = 'Aaron' />

<cfoutput>#var1.myName#</cfoutput>

This code will output 'Aaron'.  The reason is that var2 does not actually
contain a structure, rather just a 'pointer' to var1.

In the objectFactory we used, when an object was 'registered' it was put
into a structure.  When we call the create() method on the objectFactory it
checks to see if the object is supposed to be a singleton and if it is
already stored in the structure.  If it is, it merely returns a pointer to
the object.  As I said, while the code looks as if we are actually creating
a new object on each page where a gateway is needed, it is only created if
it doesn't exist or if you manually reinit the application.

In a future presentation we will cover design patterns.  In some design
patterns it would be more advantageous to use a factory like we did as
opposed to instantiating an object in the application scope.

Hope this helps.

On 11/21/06, Aaron Roberson <[EMAIL PROTECTED]> wrote:
>
> I had a hard time understanding passing by reference and by value in
> my Java class... I did download the code from Phill's blog and I
> couldn't figure out why you guys kept using the create method of the
> objectFactory on each page... now I get it.
>
> However, in this thread I am asking a much more basic question. Why
> not just create the objects in Application.cfm and ditch the whole
> objectFactory thing? It seems like it would be a whole lot easier to
> just instantiate a gateway object in Application.cfm then it is to
> register and then create each object using the objectFactory.
>
> What am I missing? There always seems to be a good reason to make
> things harder when using OOP, so there has to be something too it,
> right?
>
> Thanks,
> Aaron
>
> On 11/21/06, Scott Stroz <[EMAIL PROTECTED]> wrote:
> > Aaron,
> >
> > Thanx for watching the presentation.  I hope it helped you.
> >
> > The first part of the presentation was to demonstrate some OO
> principals,
> > and to show how you could transform a procedural application into one
> more
> > OO.  It was during this part where we were creating all the gateway
> objects
> > when we needed them.  In the latter portion of the presentation, we
> > discussed optimizing the application with the use of factories and
> caching
> > objects in a shared scope (the application scope).
> >
> > If you go to Phill's site,
> >
> http://www.phillnacelli.net/blog/index.cfm/2006/11/17/Central-PA-CFUG-Preso-Recapand
> > download the code, you will see that we used an object factory to
> > create
> > the gateway objects using the create() method.  When these gateways were
> > used in the application, they are not being created, merely returned
> from
> > the object factory.  Since the gateway objects were specified as a
> > 'singleton', only one instance of the objects will ever be in
> memory.  In
> > the application files, when we once again called the create() method of
> the
> > object factory, it merely returned a reference to the object already
> cached
> > in the application scope (Remember, complex data types, including
> objects,
> > are passed by reference).
> >
> > So while the code on the some of the files may seem like new objects are
> > being created each time a page is hit, a look at the code in
> application.cfm,
> > and in objectFactory.cfc will show that the only time a new gateway
> object
> > is created is when one does not already exist, or if you manually reinit
> the
> > applciation by adding ?reinit=true to the end of a URL.
> >
> > On 11/21/06, Aaron Roberson <[EMAIL PROTECTED]> wrote:
> > >
> > > I watched a presentation from the guys at AboutWeb.com about Object
> > > Oriented Programming in Coldfusion and Phill Nacelli's Object Factory
> > > got me wondering a few things.
> > >
> > > Is it possible to initialize all of the object gateways into the
> > > application scope in Application.cfm? It seems like it would be better
> > > to create and initialize the object once and then reference it on each
> > > page instead of creating it on each page.
> > >
> > > In Application.cfm I would have:
> > >
> > > <cfset application.personGateway =
> > > createObject("component","path.personGateway").init(application.dsn)
> > > />
> > >
> > > Then on the pages I would just do something like:
> > >
> > > <cfset getPeople = application.personGateway />
> > >
> > > What do you think, am I off somewhere with all of this OOP stuff?
> > >
> > > -Aaron
> > >
> > >
> >
> >
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:261386
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to