>Why would I want to load an object into the application scope just to
>load more objects? This is one more piece of code that has to be ran,
>maintained, suck up processes, suck up memory, to explain.... Wouldn't
>it be best to just keep it simple and call right to the CFC?


It sounds to me like you're using CFCs more as code libraries and less as 
objects, or that your particular application(s) generally only use singletons 
(one instance of an object only), like an object that handles security.  In 
these cases factories are next to useless - as you noted why would you want to 
write a factory to build one instance of an object?

Factories build instances of objects for you.  And more than that, they may 
build instances of different objects depending on the input you send to the 
factory when you request an instance.

In the simpler case, elsewhere in this thread someone already pointed out the 
benefits of using a simple factory for instantiation of a single object type 
when you are creating lots of those objects - you consolidate initialization of 
the object in one place, simplifying your code and making maintenance easier.

Consider a hypothetical situation...  I work at a university.  So I might have 
objects that represent Faculty, Staff, and Students, all inhieriting from a 
Person class.  I could use the factory to decide for me whether I need to 
instantiate a Faculty, Staff, or Student at runtime, and to centralize that 
decision making activity for me.

Another example would be a factory that creates instance of objects that wrap 
remote services..  If you had a class that generically implemented access to 
various kinds of remote data (XML files, CFCs, web services, etc).  The 
implementation of those classes would be different for each type of call, but 
the interface - the properties and method definitions - would be the same.  At 
runtime the application wouldn't need to care if it was holding a RemoteCallCFC 
or a RemoteCallWebService.  A factory would determine which class was 
necessary, instantiate it, initialize it, and pass it back to the requesting 
program.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU

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

Reply via email to