Re: CFC - separate or all in one?
Hey Andy, I think it's a similar question compared to using a framework or not using a framework. Not using a framework isn't fundamentally wrong, but it does make code-reuse, maintenance, and scaling a little more tedious. I think the goal here is abstraction. Do as much as you can so that you don't care about where you're getting the data - you're just getting it. From the other direction, the query method is pulling data for what, it doesn't know, nor does it care. Then, with CFC instances, you can make objects unique to an initialized set of data which is pretty neat instead of hard-coded methods that aren't very portable. I am still learning this as well. You might want to study the bookstore app written by Brian Kotek. Take a look at how he's instantiating all of his objects: http://www.briankotek.com/index.cfm?fuseaction=coldfusion.main take a look at the fusebox.init file. It's comparable to the application.cfm file in non-fusebox apps. Also, take a look in the COM directory for all the CFCs. I learned a lot from reading through all his code (and reading the fusebox book). Mike Andy McShane wrote: > This thread caught my eye and I would like to add a question of my own if I > may. I am relatively new to CFC's and am still getting my head around them. > I have written CFC's that only contain database calls in individual > functions that are all relative to specific areas of my site, so I have a > CFC called matchreport.cfc that handles all select, insert, update & delete > database calls, this is all that the CFC does, is there anything > fundamentally wrong with doing this or is there a better way to handle this? ~| Find out how CFTicket can increase your company's customer support efficiency by 100% http://www.houseoffusion.com/banners/view.cfm?bannerid=49 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:221829 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
RE: CFC - separate or all in one?
> -Original Message- > From: Andy McShane [mailto:[EMAIL PROTECTED] > Sent: Friday, October 21, 2005 4:31 AM > To: CF-Talk > Subject: RE: CFC - separate or all in one? > > This thread caught my eye and I would like to add a question of my own if > I > may. I am relatively new to CFC's and am still getting my head around > them. > I have written CFC's that only contain database calls in individual > functions that are all relative to specific areas of my site, so I have a > CFC called matchreport.cfc that handles all select, insert, update & > delete > database calls, this is all that the CFC does, is there anything > fundamentally wrong with doing this or is there a better way to handle > this? Well... in a way there's never anything fundamentally wrong with what works... but there's often room for improvement. ;^) I'm not one to talk about the "right" way to do OO - I'm still learning myself. But CFC's can be OO or not - so there is no "right" way. It's also hard to say because you've given little detail of what the code does. But... In the OO world something like "MatchReport" would probably represent the Match Report and everything you could do with it. So all of your related DB calls may be in there but so would methods (functions) like "Display()" which would display the HTML version of the report or "Email()" which might send the repot to somebody via email. In other words the CFC would contain everything there was to KNOW or to DO with the Match Report. A group of Match Reports might be represented as an array of CFC instances (instead of a CFQUERY). To do this you might have a helper object, perhaps called "MatchReports" (plural) which had methods like "LoadByName()" or "LoadByIDNumber()". This object could be instantiated and one of those methods run which could return an array of MatchReport instances. Now, for future maintenance, it's often better to split out your DB calls into separate objects. So, for example, your MatchReport CFC might define a "save()" method which stores changes to the report to the database. You can put the SQL for that method directly into the CFC - there's nothing "wrong" with that. However if you needed to change Databases at any time (or simply wanted the option to later distribute the code to users of other DBs) it would be harder to change things. So many people define helper objecs (usually called "Data Access Objects" or "DAOs") which only do the database calls. To change the database you only change the DAOs. (Note that "database" here actually means "persistence entity" as it doesn't really have to be a database. You're DAOs could also link to an LDAP server, XML files, flat files, or anything else which can store and hold data.) Some systems (like, say, mine) also allow the definition of the DAO on the fly. This allows the same codebase to work with any defined data source/database type without changing code. You simple add the code for any new persistence entity as a new set of DAOs and change a config file and you're done. So... I really hope that helps. I feel like I've been babbling. ;^) Jim Davis ~| Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account. http://www.houseoffusion.com/banners/view.cfm?bannerid=67 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:221821 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
RE: CFC - separate or all in one?
This thread caught my eye and I would like to add a question of my own if I may. I am relatively new to CFC's and am still getting my head around them. I have written CFC's that only contain database calls in individual functions that are all relative to specific areas of my site, so I have a CFC called matchreport.cfc that handles all select, insert, update & delete database calls, this is all that the CFC does, is there anything fundamentally wrong with doing this or is there a better way to handle this? -Original Message- From: Matthew Walker [mailto:[EMAIL PROTECTED] Sent: 21 October 2005 01:46 To: CF-Talk Subject: RE: CFC - separate or all in one? > They can be good for both, can't they? ;^) Fair enough -- I guess I meant that always using them as a library of functions is the trap many new users (e.g. me) fall into when first using CFCs. You can create utility CFCs that don't maintain state and are effectively just a collection of related methods. CFCs for manipulating images are often like this. In JavaScript, the Math class is a good example. I would suggest that as a general guideline, very few of your CFCs should be written like this. I'd also recommend you keep them in a separate folder, so you know you don't have to initialise them. ~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:221789 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
RE: CFC - separate or all in one?
> They can be good for both, can't they? ;^) Fair enough -- I guess I meant that always using them as a library of functions is the trap many new users (e.g. me) fall into when first using CFCs. You can create utility CFCs that don't maintain state and are effectively just a collection of related methods. CFCs for manipulating images are often like this. In JavaScript, the Math class is a good example. I would suggest that as a general guideline, very few of your CFCs should be written like this. I'd also recommend you keep them in a separate folder, so you know you don't have to initialise them. ~| Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account. http://www.houseoffusion.com/banners/view.cfm?bannerid=67 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:221752 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
RE: CFC - separate or all in one?
> -Original Message- > From: Matthew Walker [mailto:[EMAIL PROTECTED] > Sent: Thursday, October 20, 2005 5:08 PM > To: CF-Talk > Subject: RE: CFC - separate or all in one? > > This may be obvious but I'm a bit confued about what you're asking. > > I think it's important to note that CFCs are not merely "method > libraries" as you might create with UDFs. I agree with everything in principle, but I don't think that CFC's are "best" used as object models. Personally I think that CFCs make for truly excellent function library containers as well as object models. Since you can't actually create a real function library with UDF's CFCs are really the only way to encapsulate a function library. They can be good for both, can't they? ;^) Jim Davis ~| Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account. http://www.houseoffusion.com/banners/view.cfm?bannerid=67 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:221748 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
RE: CFC - separate or all in one?
This may be obvious but I'm a bit confued about what you're asking. I think it's important to note that CFCs are not merely "method libraries" as you might create with UDFs. They are best used when you create a CFC that represents a real-world class of objects (e.g. contacts), and you instantiate it to represent an individual object belonging to this class (e.g. "Michel"). The methods are then things like getFirstName(), setEmail(), serialise(), delete() -- i.e. they are actions you perform on the object. I would generally create a contact cfc for working with just one contact, and a contacts cfc for working with aggregate contacts -- browsing, searching, etc. The contacts cfc would generally simply return a query record set. -Original Message- From: Michel Deloux [mailto:[EMAIL PROTECTED] Sent: Friday, 21 October 2005 7:16 a.m. To: CF-Talk Subject: Re: CFC - separate or all in one? Thanx Barney. In resume: separate for concerned tasks is the best approach? This is THE OO approach, right? Cheers MD 2005/10/20, Barney Boisvert <[EMAIL PROTECTED]>: > Depends on the component(s). Are the method closely related so as to > comprise the behaviour of a single "thing", or are they varied in > nature? In general, you want each object to be concerned with a > single specific task. How big that task is can vary greatly, of > course. > > cheers, > barneyb > > On 10/20/05, Michel Deloux <[EMAIL PROTECTED]> wrote: > > Hi all > > > > what's the best: separate functions/methods in several components or > > include all methods in a same component? > > > > Cheers > > > > MD > > = > > > -- > Barney Boisvert > [EMAIL PROTECTED] > 360.319.6145 > http://www.barneyb.com/ > > Got Gmail? I have 100 invites. > > ~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:221738 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Re: CFC - separate or all in one?
Thanx Barney. In resume: separate for concerned tasks is the best approach? This is THE OO approach, right? Cheers MD 2005/10/20, Barney Boisvert <[EMAIL PROTECTED]>: > Depends on the component(s). Are the method closely related so as to > comprise the behaviour of a single "thing", or are they varied in > nature? In general, you want each object to be concerned with a > single specific task. How big that task is can vary greatly, of > course. > > cheers, > barneyb > > On 10/20/05, Michel Deloux <[EMAIL PROTECTED]> wrote: > > Hi all > > > > what's the best: separate functions/methods in several components or > > include all methods in a same component? > > > > Cheers > > > > MD > > = > > > -- > Barney Boisvert > [EMAIL PROTECTED] > 360.319.6145 > http://www.barneyb.com/ > > Got Gmail? I have 100 invites. > > ~| Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account. http://www.houseoffusion.com/banners/view.cfm?bannerid=67 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:221718 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Re: CFC - separate or all in one?
Depends on the component(s). Are the method closely related so as to comprise the behaviour of a single "thing", or are they varied in nature? In general, you want each object to be concerned with a single specific task. How big that task is can vary greatly, of course. cheers, barneyb On 10/20/05, Michel Deloux <[EMAIL PROTECTED]> wrote: > Hi all > > what's the best: separate functions/methods in several components or > include all methods in a same component? > > Cheers > > MD > = -- Barney Boisvert [EMAIL PROTECTED] 360.319.6145 http://www.barneyb.com/ Got Gmail? I have 100 invites. ~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:221715 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
CFC - separate or all in one?
Hi all what's the best: separate functions/methods in several components or include all methods in a same component? Cheers MD ~| Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account. http://www.houseoffusion.com/banners/view.cfm?bannerid=67 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:221711 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54