Re: whats the purpose of an objectFactory?
As others are indicating, factories become more and more useful as your application becomes more and more complex. In the first app i built using CFC's, after about a year of iterations and improvements, i had well over 1800 CreateObject() calls in the thing. One day a problem arose because of the mapping to those objects. I wanted to fork the development, maintain the current version and keep going with a new one. So the 2 versions couldn't use the same mapping. I was nervous about doing a search and replace through the whole application, because i wasn't sure if it would break anything. So i carefully stepped through each CreateObject() call. It took me a long time, and i made a few mistakes along the way. All in all, i think it took me the better part of a day more or less to deal with it, after dithering about my approach, working through all those CreateObject() calls, and fixing my mistakes. It was on that day that the usefulness of factories really came home to me. If i had encapsulated all my CreateObject() calls in a factory, i could have simply copied the original, ran a quick search and replace on the copy, and even could have swapped the new factory in for the old one. If i had to possible fix a mapping issue every time i installed an instance of my app, if it were an ASP type of thing, then i'd only need to adjust the factory. Which makes all the instances of my app MUCH more maintainable, because i can roll out bug fixes to all the instances without fiddling with each one. Mike's comment about how CFC use has increased also applied to me. It didn't make sense to use a factory to me at first either. But the need crept up on me. That's the reason i'd suggest to someone for getting into factories early. Encapsulating object creation make your app much more flexible and easy to maintain, down the road. It's really true, even in ColdFusion. Nando On 12/12/06, Mike Kear [EMAIL PROTECTED] wrote: My experience has been thinking i only have a few objects so it's not really worth the effort of building a factory. But i built one anyway for the experience. But when i look at that first OOP project now, a year later, i see my site which was originally going to have only 10 objects now has more than 50. I'm REALLY glad i built the factory now! Once you see how great this OOP thing is, you start bolting on applications like there's no tomorrow, and complexity starts coming looking for you. When you think you are only going to have a few objects, I reckon for most cases, that's only because you have missed something. And you're going to get more complexity anyway. Cheers Mike Kear Windsor, NSW, Australia Adobe Certified Advanced ColdFusion Developer AFP Webworks http://afpwebworks.com ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month On 12/12/06, Judith Dinowitz [EMAIL PROTECTED] wrote: I'm going to look for some decent example of a objectFactory and do some testing to see if there is a performance hit. That sounds like a great idea. Here is an objectFactory to look at and compare with: http://www.phillnacelli.net/blog/index.cfm/2006/11/21/ObjectFactory-Explained Please let us know what you find. -Aaron Well, as I believe Chris Scott explained in his article ColdSpring Fundamentals (FAQU 2), object factories really make a difference when your application gets highly complex and you start having many more objects to initialize with dependencies... That's what ColdSpring tries to do, to manage the objects for you. If you've only got 8 or 9 objects, then maybe an object factory is not for you. Judith ~| 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:263698 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: whats the purpose of an objectFactory?
PS ... On the way to the post office to check my mail, i realized i forgot to say something in my reply. :-) Your approach of creating all your objects in Application.cfm and placing them in application scope kind of encapsulates your object creation for now. But this approach will break down the moment you need an object in a different scope, say session scope. And the way it seems you are doing it is not as efficient as it could be. I'm looking at your example and assuming it's verbatim: cfset application.objectOne = CreateObject('component', 'cfc.navigation') cfset application.objectTwo = CreateObject('component', 'cfc.users') cfset application.objectThree = CreateObject('component', 'cfc.email') In this way, you recreate the objects for each request. There's little point in using application scope in this case. It would be much more efficient if you created a singleton factory in application.cfm like so (with a double lock as shown, to make sure you have only one instance of the Factory in application scope): cfif NOT StructKeyExists(application,Factory) cflock name=factoryLock Timeout=10 THROWONTIMEOUT=No Type=Exclusive cfif NOT StructKeyExists(application,Factory) cfset application.Factory = CreateObject('component',' cfc.Factory').init(passInAppSettingsHere) /cfif /cflock /cfif And then in Factory.init(), you can instantiate any singletons you need into the variables scope of the factory and they'll persist then effectively in application scope for the duration of your application. A singleton, if you don't know the term, is one and only one instance of an object that persists in application scope in CF. I guess you could also use the term for a server scoped object. --- simple Factory.cfc example --- cffunction name=init access=public returntype=Factory output=no cfargument name=AppSettings type=any required=Yes/ cfset variables.AppSettings = arguments.AppSettings / cfset variables.Navigation = createNavigation() / cfset variables.Navigation.init(variables.AppSettings.getDsn()) / cfreturn this / /cffunction cffunction name=createNavigation access=public returntype=any output=no cfset var Navigation = createObject('component','cfc.Navigation') / cfreturn Navigation / /cffunction cffunction name=getNavigation access=public returntype=any output=no cfreturn variables.Navigation / /cffunction ... When you need your persisted Navigation object somewhere in your application, you can do this: application.Factory.getNavigation ().getBreadcrumb(uniqueIdentifierForThisPage) And if you need the navigation for a particular visitor you, could do something like this: session.navigation = application.Factory.createNavigation() .. session.navigation.setUserRole(session.User.getRole()) session.navigation.getUserNav() The example might be a bit contrived, but i'm only trying to show that with a factory, you can cache objects in application scope within the factory itself, which means you only need to deal with double locking in one place for singletons. Or you can use the same factory to create objects for one time use or session scoped objects. Different people will design factories in different ways, and use different naming conventions for the functions. The more sophisticated your factory, the more flexible and abstract. You could for instance build a load() function something like this: cffunction name=load access=public returntype=any output=false cfargument name=objectName required=Yes type=string / cfargument name=isSingleton default=false type=boolean / cfif arguments.isSingleton IS true cfif StructKeyExists(variables,arguments.objectName) return variables[arguments.objectName] cfelse create arguments.objectName put it in variables scope return variables[arguments.objectName] /cfif cfelse create arguments.objectName return it /cfif /cffunction That's fine, but what if you need to pass in parameters to your init() function? how would you do that? What if one of your parameters is another object? Now we're getting close to ColdSpring, so we might as well use it. But for most people starting out with factories, it's probably easier to get a feel for them using a simple factory you build yourself that has separate create() or get() functions for each object. Once the usefulness of it really clicks, then ColdSpring might be the next step. But i can guarantee to you that factories can be very useful. You just need to take a few more steps into deeper water with your CFC use and it will become apparent. On 12/12/06, Nando [EMAIL PROTECTED] wrote: As others are indicating, factories become more and more useful as your application becomes more and more complex. In the first app i built using CFC's, after about a year of iterations and improvements, i had well over 1800 CreateObject() calls in the
Re: whats the purpose of an objectFactory?
On 12/12/06, Nando [EMAIL PROTECTED] wrote: In the first app i built using CFC's, after about a year of iterations and improvements, i had well over 1800 CreateObject() calls in the thing. By the power of Greyskull! Are you trying to take over the world with your 1800 objects? ;-) We use a lot of object calls thru out our sites. The way we have managed them is with a masterController. It is mapped to all of the sites and handles all of the work. Sort of MVC but not really. We do use a lot of singletons. I guess that is why I'm having a hard time seeing the benefit of a factory. We can instantiate all the objects we need when the app gets initialized. The app only gets reinitialized when it is necessary. So maybe we don't need to worry about a factory at this point but I still want to learn more about how they can help. I'm going to do some testing to see if there is any cost to using one. When I get the results I'll pass them on to the group. Phil ~| 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:263726 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: whats the purpose of an objectFactory?
I do use this technique. cfif NOT isDefined('application.layout') OR isDefined('url.appInit') I just didn't want to take the time to write it out though. hahaha Thanks for posting that though. I think there are a lot of people that don't know that they need to do these sort of things. Thanks again Nando. On 12/12/06, Nando [EMAIL PROTECTED] wrote: PS ... On the way to the post office to check my mail, i realized i forgot to say something in my reply. :-) Your approach of creating all your objects in Application.cfm and placing them in application scope kind of encapsulates your object creation for now. But this approach will break down the moment you need an object in a different scope, say session scope. And the way it seems you are doing it is not as efficient as it could be. I'm looking at your example and assuming it's verbatim: cfset application.objectOne = CreateObject('component', 'cfc.navigation') cfset application.objectTwo = CreateObject('component', 'cfc.users') cfset application.objectThree = CreateObject('component', 'cfc.email') In this way, you recreate the objects for each request. There's little point in using application scope in this case. It would be much more efficient if you created a singleton factory in application.cfm like so (with a double lock as shown, to make sure you have only one instance of the Factory in application scope): cfif NOT StructKeyExists(application,Factory) cflock name=factoryLock Timeout=10 THROWONTIMEOUT=No Type=Exclusive cfif NOT StructKeyExists(application,Factory) cfset application.Factory = CreateObject('component',' cfc.Factory').init(passInAppSettingsHere) /cfif /cflock /cfif And then in Factory.init(), you can instantiate any singletons you need into the variables scope of the factory and they'll persist then effectively in application scope for the duration of your application. A singleton, if you don't know the term, is one and only one instance of an object that persists in application scope in CF. I guess you could also use the term for a server scoped object. --- simple Factory.cfc example --- cffunction name=init access=public returntype=Factory output=no cfargument name=AppSettings type=any required=Yes/ cfset variables.AppSettings = arguments.AppSettings / cfset variables.Navigation = createNavigation() / cfset variables.Navigation.init(variables.AppSettings.getDsn()) / cfreturn this / /cffunction cffunction name=createNavigation access=public returntype=any output=no cfset var Navigation = createObject('component','cfc.Navigation') / cfreturn Navigation / /cffunction cffunction name=getNavigation access=public returntype=any output=no cfreturn variables.Navigation / /cffunction ... When you need your persisted Navigation object somewhere in your application, you can do this: application.Factory.getNavigation ().getBreadcrumb(uniqueIdentifierForThisPage) And if you need the navigation for a particular visitor you, could do something like this: session.navigation = application.Factory.createNavigation() .. session.navigation.setUserRole(session.User.getRole()) session.navigation.getUserNav() The example might be a bit contrived, but i'm only trying to show that with a factory, you can cache objects in application scope within the factory itself, which means you only need to deal with double locking in one place for singletons. Or you can use the same factory to create objects for one time use or session scoped objects. Different people will design factories in different ways, and use different naming conventions for the functions. The more sophisticated your factory, the more flexible and abstract. You could for instance build a load() function something like this: cffunction name=load access=public returntype=any output=false cfargument name=objectName required=Yes type=string / cfargument name=isSingleton default=false type=boolean / cfif arguments.isSingleton IS true cfif StructKeyExists(variables,arguments.objectName) return variables[arguments.objectName] cfelse create arguments.objectName put it in variables scope return variables[arguments.objectName] /cfif cfelse create arguments.objectName return it /cfif /cffunction That's fine, but what if you need to pass in parameters to your init() function? how would you do that? What if one of your parameters is another object? Now we're getting close to ColdSpring, so we might as well use it. But for most people starting out with factories, it's probably easier to get a feel for them using a simple factory you build yourself that has separate create() or get() functions for each object. Once the usefulness of it really clicks, then ColdSpring might be the next step. But i can guarantee to you
Re: whats the purpose of an objectFactory?
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
whats the purpose of an objectFactory?
I have read a lot about people making their own objectFactory and I still don't see the need for one. Can some one please give me a reason why I would need to use one? So far I have yet to find a reason not to call to the objects directly when I need them. My lack of understanding makes me think it is just adding more code than is required. -- Phil ~| 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:263537 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: whats the purpose of an objectFactory?
The real benefits I have found are: 1) Objects are initialised in one place only, so if the init arguments change, then I only need to change one piece of code. 2) Objects are created in one place only, so if the location of the component changes, then I only need to change one piece of code. 3) Less code! application.myfactory.getInstance() is less code than createobject(component,path.to.my.component).init(application.dsn, application.somethingelse) On 11/12/06, Phill B [EMAIL PROTECTED] wrote: I have read a lot about people making their own objectFactory and I still don't see the need for one. Can some one please give me a reason why I would need to use one? So far I have yet to find a reason not to call to the objects directly when I need them. My lack of understanding makes me think it is just adding more code than is required. -- Phil ~| 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:263539 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: whats the purpose of an objectFactory?
I am just working through OOP stuff myself... Regarding the object factory, would you have a separate factory for each object, say the object was User, like UserFactory? So if you were instantiating a User and then populating the bean from the db, (assuming all the obvious stuff, your classes are init'd into the Application scope etc.) the call would be cfset tempUser = Application.UserFactory.getInstance() cfset myUser = Application.UserDAO.read(tempUser) Or is there another best practice for handling a factory? Also, what is the generally accepted way to init your classes into the Application scope, is this just done in App.cfm or App.cfc? Thanks for any guidance. -- Josh - Original Message - From: Adrian [EMAIL PROTECTED] To: CF-Talk cf-talk@houseoffusion.com Sent: Monday, December 11, 2006 8:50 AM Subject: Re: whats the purpose of an objectFactory? The real benefits I have found are: 1) Objects are initialised in one place only, so if the init arguments change, then I only need to change one piece of code. 2) Objects are created in one place only, so if the location of the component changes, then I only need to change one piece of code. 3) Less code! application.myfactory.getInstance() is less code than createobject(component,path.to.my.component).init(application.dsn, application.somethingelse) On 11/12/06, Phill B [EMAIL PROTECTED] wrote: I have read a lot about people making their own objectFactory and I still don't see the need for one. Can some one please give me a reason why I would need to use one? So far I have yet to find a reason not to call to the objects directly when I need them. My lack of understanding makes me think it is just adding more code than is required. -- Phil ~| 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:263546 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: whats the purpose of an objectFactory?
Also, what is the generally accepted way to init your classes into the Application scope, is this just done in App.cfm or App.cfc? Thanks for any guidance. I am not one to give guidance since I am new to all this myself, but... I don't use an object factory. Instead I init all of my services, gateways and DAOs in Application.cfm. This provides the same benefits Adrian mentioned for using object factories (there are probably other benefits to using object factories that my approach does not benefit from). I have also chosen to place Application.cfm files in each directory. That way I am only initting objects that will be used in that directories files. If all of my objects for the entire application were initted in one Application.cfm there would a rather long delay when someone first visits the site. On the other hand, Phill Nacelli has created an object factory that looks pretty good. I was going to use it but he took a while to post an explanation about it on his blog and I had to continue developing my application so... maybe next time. He has since blogged about it here: http://www.phillnacelli.net/blog/index.cfm/2006/11/21/ObjectFactory-Explained HTH, Aaron ~| 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:263567 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: whats the purpose of an objectFactory?
He has since blogged about it here: http://www.phillnacelli.net/blog/index.cfm/2006/11/21/ObjectFactory-Explained Thanks for pointing me to that article Aaron. Very helpful! -- Josh ~| 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:263577 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: whats the purpose of an objectFactory?
I do all my work in application.cfm file as well. I load the 7 or 8 objects I need and I'm done with it. I just don't see how there code be a speed benefit. 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? I don't know what is right or wrong when it comes to objectFactories. That is why I am asking the question. On 12/11/06, Aaron Roberson [EMAIL PROTECTED] wrote: I am not one to give guidance since I am new to all this myself, but... I don't use an object factory. Instead I init all of my services, gateways and DAOs in Application.cfm. This provides the same benefits Adrian mentioned for using object factories (there are probably other benefits to using object factories that my approach does not benefit from). I have also chosen to place Application.cfm files in each directory. That way I am only initting objects that will be used in that directories files. If all of my objects for the entire application were initted in one Application.cfm there would a rather long delay when someone first visits the site. On the other hand, Phill Nacelli has created an object factory that looks pretty good. I was going to use it but he took a while to post an explanation about it on his blog and I had to continue developing my application so... maybe next time. He has since blogged about it here: http://www.phillnacelli.net/blog/index.cfm/2006/11/21/ObjectFactory-Explained HTH, Aaron ~| 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:263583 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: whats the purpose of an objectFactory?
I think the issue is not up-front object instantiation. That is simple. The beauty of the Object factory I think is that at any time down the road, any part of the application that has access to the object factory can request object instantiation without having to know how it is done. This cannot be done via the Application.cfc unless it was a component method of the Application.cfc. .. Ben Nadel Certified Advanced ColdFusion MX7 Developer www.bennadel.com Need ColdFusion Help? www.bennadel.com/ask-ben/ -Original Message- From: Phill B [mailto:[EMAIL PROTECTED] Sent: Monday, December 11, 2006 2:55 PM To: CF-Talk Subject: Re: whats the purpose of an objectFactory? I do all my work in application.cfm file as well. I load the 7 or 8 objects I need and I'm done with it. I just don't see how there code be a speed benefit. 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? I don't know what is right or wrong when it comes to objectFactories. That is why I am asking the question. On 12/11/06, Aaron Roberson [EMAIL PROTECTED] wrote: I am not one to give guidance since I am new to all this myself, but... I don't use an object factory. Instead I init all of my services, gateways and DAOs in Application.cfm. This provides the same benefits Adrian mentioned for using object factories (there are probably other benefits to using object factories that my approach does not benefit from). I have also chosen to place Application.cfm files in each directory. That way I am only initting objects that will be used in that directories files. If all of my objects for the entire application were initted in one Application.cfm there would a rather long delay when someone first visits the site. On the other hand, Phill Nacelli has created an object factory that looks pretty good. I was going to use it but he took a while to post an explanation about it on his blog and I had to continue developing my application so... maybe next time. He has since blogged about it here: http://www.phillnacelli.net/blog/index.cfm/2006/11/21/ObjectFactory-Ex plained HTH, Aaron ~| 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:263589 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: whats the purpose of an objectFactory?
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? I think the idea is that as long as you have sufficient RAM, a call to the Application scope will always be quicker than than a call to the CFC. If you have a gig of RAM dedicated to CF, a few MB of objects is negligible. If your RAM is an issue, it's probably fine to call right to the CFC. Also Adrian gave a few good reasons to take the objectFactory approach: the main one being you are re-using code rather than duplicating code in different places. -- Josh ~| 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:263593 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: whats the purpose of an objectFactory?
Another reason why I did not use an object factory is because I noted the fact that you have to register all the DAO's, gateways and beans with the full path in Application.cfm. It seemed just as easy to instantiate all of my objects directly in Application.cfm and assign them to the application scope. With my current method I am still only setting the path in one place. I can also reference all of my objects from any part of the application that is in the same directory as Application.cfm without having to know how it is instantiated. However, I think that Phill's ObjectFactory.cfc does not instantiate the objects when registered in Application.cfm. Instead, I believe that all of the details are placed in a struct that can be be referenced at any time. The advantage of this would be that the objects are not instantiated until they are actually used. You still get the benefit of having only one copy of the object in memory and you do not have to use a full path to the object when instantiating it in the view or controller. If that is the case, I just talked myself into using Phill's ObjectFactory.cfc. The benefit over my current method would be that the objects are not instantiated until they are used. Even if a request to instantiate the object is made several times across several pages, there is still only one copy of the object in memory because complex objects are passed by reference. -Aaron ~| 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:263605 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: whats the purpose of an objectFactory?
On 12/11/06, Josh Nathanson [EMAIL PROTECTED] wrote: I think the idea is that as long as you have sufficient RAM, a call to the Application scope will always be quicker than than a call to the CFC. If you have a gig of RAM dedicated to CF, a few MB of objects is negligible. If your RAM is an issue, it's probably fine to call right to the CFC. Also Adrian gave a few good reasons to take the objectFactory approach: the main one being you are re-using code rather than duplicating code in different places. -- Josh But there is less code being used with out the objectFactory. I could have this in my application.cfm cfset application.objectOne = CreateObject('component', 'cfc.navigation') cfset application.objectTwo = CreateObject('component', 'cfc.users') cfset application.objectThree = CreateObject('component', 'cfc.email') Three lines to load instantiate an object. Or you could have this in the application.cfm cfset application.objectFactory= CreateObject('component', 'cfc.objectFactory') cfset application.objectFactory.register('objectOne') cfset application.objectFactory.register('objectTwo') cfset application.objectFactory.register('objectThree') This takes one more line of code in the application.cfm file plus what ever you have written into your objectFactory. Now I have the objectFactory in memory that only gets used when I initialize my app. Plus, I have more code to maintain inside the objectFactory. The beauty of ColdFusion is how simple it is to get things done. Why would I want to go ruin that by jumping on the bandwagon to the factory? I'm not trying to say that objectFartories are bad. M'kay I'm just trying to find a way that they would help me. Phil ~| 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:263636 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: whats the purpose of an objectFactory?
On 12/11/06, Aaron Roberson [EMAIL PROTECTED] wrote: If that is the case, I just talked myself into using Phill's ObjectFactory.cfc. The benefit over my current method would be that the objects are not instantiated until they are used. Even if a request to instantiate the object is made several times across several pages, there is still only one copy of the object in memory because complex objects are passed by reference. -Aaron But why not go ahead and get the job done with the initial load of the application? Why wait for it to happen two page loads later? Phil ~| 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:263642 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: whats the purpose of an objectFactory?
But why not go ahead and get the job done with the initial load of the application? Why wait for it to happen two page loads later? If you initialize all of your objects with the start of your application then the user will have to wait until the objects are all initialized before they can view any pages. As you know, CFC's are pretty heavy and createObject, though it is better than cfinvoke, still takes time. ANSWER: If the application waits two pages later, the visitor to your site will not have to. I put my users first. -Aaron ~| 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:263654 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: whats the purpose of an objectFactory?
If you initialize all of your objects with the start of your application then the user will have to wait until the objects are all initialized before they can view any pages. This can be overcome by extending your Application timeout. If your app only gets hit once every two days, make the Application timeout three days. Then in App.cfm you do something like cfif not isDefined(Application.myObject) or isDefined(url.reloadObjects) instantiate /cfif This way the object will not re-instantiate every time the page is hit, only if it is not yet defined; or if you do want to explicitly reload your objects, set the url variable reloadObjects. -- Josh - Original Message - From: Aaron Roberson [EMAIL PROTECTED] To: CF-Talk cf-talk@houseoffusion.com Sent: Monday, December 11, 2006 2:23 PM Subject: Re: whats the purpose of an objectFactory? But why not go ahead and get the job done with the initial load of the application? Why wait for it to happen two page loads later? If you initialize all of your objects with the start of your application then the user will have to wait until the objects are all initialized before they can view any pages. As you know, CFC's are pretty heavy and createObject, though it is better than cfinvoke, still takes time. ANSWER: If the application waits two pages later, the visitor to your site will not have to. I put my users first. -Aaron ~| 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:263659 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: whats the purpose of an objectFactory?
On 12/11/06, Aaron Roberson [EMAIL PROTECTED] wrote: If you initialize all of your objects with the start of your application then the user will have to wait until the objects are all initialized before they can view any pages. As you know, CFC's are pretty heavy and createObject, though it is better than cfinvoke, still takes time. ANSWER: If the application waits two pages later, the visitor to your site will not have to. I put my users first. -Aaron I have to ask, how many objects are people trying to instantiate? I have maybe 8 or 9 objects to load into the application scope. I'll tell you right now that there wont be any noticeable savings doing with the initialization of the app or waiting until you need it. To make sure its understood, I'm talking about objects that will persist until the app times out. Not some thing that would be instantiated on every page load. I'm going to look for some decent example of a objectFactory and do some testing to see if there is a performance hit. I'm getting the feeling that people are starting to use objectFactories because its cool and new. Not because it will benefit the performance of their applications. And we all know that a high performance app makes the users happy. Phil ~| 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:263662 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: whats the purpose of an objectFactory?
I'm going to look for some decent example of a objectFactory and do some testing to see if there is a performance hit. That sounds like a great idea. Here is an objectFactory to look at and compare with: http://www.phillnacelli.net/blog/index.cfm/2006/11/21/ObjectFactory-Explained Please let us know what you find. -Aaron ~| 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:263663 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: whats the purpose of an objectFactory?
I'm going to look for some decent example of a objectFactory and do some testing to see if there is a performance hit. That sounds like a great idea. Here is an objectFactory to look at and compare with: http://www.phillnacelli.net/blog/index.cfm/2006/11/21/ObjectFactory-Explained Please let us know what you find. -Aaron Well, as I believe Chris Scott explained in his article ColdSpring Fundamentals (FAQU 2), object factories really make a difference when your application gets highly complex and you start having many more objects to initialize with dependencies... That's what ColdSpring tries to do, to manage the objects for you. If you've only got 8 or 9 objects, then maybe an object factory is not for you. Judith ~| 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:263676 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: whats the purpose of an objectFactory?
My experience has been thinking i only have a few objects so it's not really worth the effort of building a factory. But i built one anyway for the experience. But when i look at that first OOP project now, a year later, i see my site which was originally going to have only 10 objects now has more than 50. I'm REALLY glad i built the factory now! Once you see how great this OOP thing is, you start bolting on applications like there's no tomorrow, and complexity starts coming looking for you. When you think you are only going to have a few objects, I reckon for most cases, that's only because you have missed something. And you're going to get more complexity anyway. Cheers Mike Kear Windsor, NSW, Australia Adobe Certified Advanced ColdFusion Developer AFP Webworks http://afpwebworks.com ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month On 12/12/06, Judith Dinowitz [EMAIL PROTECTED] wrote: I'm going to look for some decent example of a objectFactory and do some testing to see if there is a performance hit. That sounds like a great idea. Here is an objectFactory to look at and compare with: http://www.phillnacelli.net/blog/index.cfm/2006/11/21/ObjectFactory-Explained Please let us know what you find. -Aaron Well, as I believe Chris Scott explained in his article ColdSpring Fundamentals (FAQU 2), object factories really make a difference when your application gets highly complex and you start having many more objects to initialize with dependencies... That's what ColdSpring tries to do, to manage the objects for you. If you've only got 8 or 9 objects, then maybe an object factory is not for you. Judith ~| 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:263677 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4