On 9/27/07, Alan <[EMAIL PROTECTED]> wrote: > I'm just realising how handy onMissingMethod() in CF8 can be.
Thank you (it's there because I asked Ashwin Mathew to add it - so ColdFusion could be more like Ruby - :method_missing - and Smalltalk - #doesNotUnderstand). > typing but wondered if I should just use onMissingMethod() to handle > this instead and keep the CFC's smaller. Well, I happen to really like the convenience of automatic getters and setters so I have added a bunch of code to WEB-INF/cftags/component.cfc to handle this automatically: http://org-corfield-cfmx.googlecode.com/svn/trunk/wwwroot/org/corfield/component.cfc A couple of caveats: 1. The magic="true" attributes on the <cffunction> tags are there so my local version of Transfer can spot methods from component.cfc and not try to add/remove them when handling pooled objects. Yes, I run a locally modified version of Transfer. Mark Mandel knows. We've talked about a way for Transfer to handle this automatically somehow but it's low priority. 2. The call() method allows you to write proxies - see my blog entry on the automatic transaction-wrapping proxy that uses onMissingMethod(). The call() method is fugly but it has to handle both named and positional arguments (I can explain the problem if anyone really cares). 3. Implementing getXxx() and setXxx() like this - as runtime methods - has an overhead that generated getXxx() and setXxx() methods do not. onMissingMethod() itself is very fast but any code you write in it will naturally have more overhead in emulating a specific method call than actually executing a specific method. > I've read stuff on the debate between whats best - getFirstname() or > get("firstname") and it seems there are 2 camps that can't agree. I > wonder if onMissingMethod() will produce the same polarised opinions. Probably. I really don't like the "generic get/set" approach but of course onMissingMethod() provides syntactic sugar for essentially the same thing... > Also, what other design issues are people using onMissingMethod() to > address? I'm tempted to use it to provide generic find_by methods on my table data gateway objects (which is what Rails does in its Active Record implementation), e.g., result = userGateway.find_by_email_and_password("[EMAIL PROTECTED]","secret"); result = userGateway.find_by_firstname_and_lastname("Sean","Corfield"); Mostly I use it for proxies (lightweight AOP stuff) and I believe ColdSpring 2.0 will use that to implement AOP (and therefore be CF8-specific). Maybe Mark Mandel will end up using it for Transfer as well (he's already using duplicate() if you're on CF8). -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CFCDev" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfcdev?hl=en -~----------~----~----~----~------~----~------~--~---
