RE: Init method and getters / setters in cfc
Thanks Brian, I didn't realize there was a variables.instance structure =) Here is the lowdown I got from everyone's comments: If I was working either with a team, using coldspring, or working on a large project or public facing components, I would probably generate individual getters / setters for each internal value I would want to work with. As many have mentioned, this makes the component self documenting and adds type checking. The project I am working on now simply requires that I be able to use this for several different sub-companies down the road, and the only one that will touch this code (at least in the foreseeable future) is me. I have an init method that accepts a structure to setup all datasources and other per-company settings, so I think my generic getter / setter should work fine in this instance. Thanks to everyone for their reply's, I always learn something new. =) Chris Peterson Gainey IT Adobe Certified Advanced Coldfusion Developer -Original Message- From: Brian Kotek Sent: Monday, July 09, 2007 10:27 PM To: CF-Talk Subject: Re: Init method and getters / setters in cfc It's so trivial to generate the code for getters and setters that I don't really see the point in having generic getters and setters like this. As Ben says, you lose the API for your component. You have no type checking (if that's your thing). You lose the ability to seamlessly change the getter or setter later if the need arises. And if you want to use ColdSpring to inject dependencies, you're either out of luck, or almost as bad, you have a mixed API where some properties have their own setters and others use the generic setter. Also, an aside, there's no reason to use Evaluate() here. Just do cfreturn variables.instance[arguments.name] /. Regards, Brian ~| ColdFusion MX7 by Adobe® Dyncamically transform webcontent into Adobe PDF with new ColdFusion MX7. Free Trial. http://www.adobe.com/products/coldfusion?sdid=RVJV Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283376 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Init method and getters / setters in cfc
Well that isn't going to work for all variable types and seems a little clumsy. This method relies on top much which may not be present in a more complex CFC application setup. This e-mail is from Reed Exhibitions (Gateway House, 28 The Quadrant, Richmond, Surrey, TW9 1DN, United Kingdom), a division of Reed Business, Registered in England, Number 678540. It contains information which is confidential and may also be privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of distribution, copying or use of this communication or the information in it is strictly prohibited and may be unlawful. If you have received this communication in error please return it to the sender or call our switchboard on +44 (0) 20 89107910. The opinions expressed within this communication are not necessarily those expressed by Reed Exhibitions. Visit our website at http://www.reedexpo.com -Original Message- From: Peterson, Chris To: CF-Talk Sent: Mon Jul 09 20:51:48 2007 Subject: Init method and getters / setters in cfc A lot of cfc's using init and 'good' OO practices have functions like getDSN(), setDSN('Blah') littered throughout. Can I ask any guru out there why you wouldn't use simple get('keyname') and set('keyname','keyvalue') like the following? cffunction name=get access=public output=no returntype=any cfargument name=name required=true type=string cfreturn evaluate('variables.' arguments.name) / /cffunction cffunction name=set access=public output=no returntype=void cfargument name=name required=true type=string cfargument name=value required=true type=any cfset variables[arguments.name] = arguments.value / /cffunction Then instead of littering your cfc with numerous getters / setter, you have 2 methods that should be able to handle simple or complex values without any problems with much less code. Chris Peterson Gainey IT Adobe Certified Advanced Coldfusion Developer ~| ColdFusion MX7 and Flex 2 Build sales marketing dashboard RIAâs for your business. Upgrade now http://www.adobe.com/products/coldfusion/flex2?sdid=RVJT Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283308 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: Init method and getters / setters in cfc
Chris, While I don't know what is *right*, here are the arguments that I have heard against the generic getter/setter: * The CFC is not self documenting. Looking at its functions does not give you any insight into what it can set/get. * Not clear on what should be returned if an invalid get is requested. * It makes extending a component more difficult because the parent component now has to be smarter about where it looks for its data. Take that with a grain of salt ;) .. Ben Nadel Certified Advanced ColdFusion MX7 Developer www.bennadel.com Need ColdFusion Help? www.bennadel.com/ask-ben/ -Original Message- From: Peterson, Chris [mailto:[EMAIL PROTECTED] Sent: Monday, July 09, 2007 3:52 PM To: CF-Talk Subject: Init method and getters / setters in cfc A lot of cfc's using init and 'good' OO practices have functions like getDSN(), setDSN('Blah') littered throughout. Can I ask any guru out there why you wouldn't use simple get('keyname') and set('keyname','keyvalue') like the following? cffunction name=get access=public output=no returntype=any cfargument name=name required=true type=string cfreturn evaluate('variables.' arguments.name) / /cffunction cffunction name=set access=public output=no returntype=void cfargument name=name required=true type=string cfargument name=value required=true type=any cfset variables[arguments.name] = arguments.value / /cffunction Then instead of littering your cfc with numerous getters / setter, you have 2 methods that should be able to handle simple or complex values without any problems with much less code. Chris Peterson Gainey IT Adobe Certified Advanced Coldfusion Developer ~| ColdFusion MX7 by Adobe® Dyncamically transform webcontent into Adobe PDF with new ColdFusion MX7. Free Trial. http://www.adobe.com/products/coldfusion?sdid=RVJV Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283309 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: Init method and getters / setters in cfc
Hal Helms uses the same style of coding you're talking about. A master get/set method where you pass in the value AND name of the property you're trying to access. andy -Original Message- From: Peterson, Chris [mailto:[EMAIL PROTECTED] Sent: Monday, July 09, 2007 2:52 PM To: CF-Talk Subject: Init method and getters / setters in cfc A lot of cfc's using init and 'good' OO practices have functions like getDSN(), setDSN('Blah') littered throughout. Can I ask any guru out there why you wouldn't use simple get('keyname') and set('keyname','keyvalue') like the following? cffunction name=get access=public output=no returntype=any cfargument name=name required=true type=string cfreturn evaluate('variables.' arguments.name) / /cffunction cffunction name=set access=public output=no returntype=void cfargument name=name required=true type=string cfargument name=value required=true type=any cfset variables[arguments.name] = arguments.value / /cffunction Then instead of littering your cfc with numerous getters / setter, you have 2 methods that should be able to handle simple or complex values without any problems with much less code. Chris Peterson Gainey IT Adobe Certified Advanced Coldfusion Developer ~| CF 8 â Scorpio beta now available, easily build great internet experiences â Try it now on Labs http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_adobecf8_beta Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283311 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: Init method and getters / setters in cfc
I would add your component is now completely mutable. A developer can add any data they want which may or may not be a big deal depending on ones thinking on such things and what the component is meant to do. An example that shows this code is going to accept any and all input such as this. aObj.set(myOwnSillyvar,Some really bad data) Ian Ben Nadel wrote: Chris, While I don't know what is *right*, here are the arguments that I have heard against the generic getter/setter: * The CFC is not self documenting. Looking at its functions does not give you any insight into what it can set/get. * Not clear on what should be returned if an invalid get is requested. * It makes extending a component more difficult because the parent component now has to be smarter about where it looks for its data. Take that with a grain of salt ;) .. Ben Nadel Certified Advanced ColdFusion MX7 Developer www.bennadel.com Need ColdFusion Help? www.bennadel.com/ask-ben/ -Original Message- From: Peterson, Chris [mailto:[EMAIL PROTECTED] Sent: Monday, July 09, 2007 3:52 PM To: CF-Talk Subject: Init method and getters / setters in cfc A lot of cfc's using init and 'good' OO practices have functions like getDSN(), setDSN('Blah') littered throughout. Can I ask any guru out there why you wouldn't use simple get('keyname') and set('keyname','keyvalue') like the following? cffunction name=get access=public output=no returntype=any cfargument name=name required=true type=string cfreturn evaluate('variables.' arguments.name) / /cffunction cffunction name=set access=public output=no returntype=void cfargument name=name required=true type=string cfargument name=value required=true type=any cfset variables[arguments.name] = arguments.value / /cffunction Then instead of littering your cfc with numerous getters / setter, you have 2 methods that should be able to handle simple or complex values without any problems with much less code. Chris Peterson Gainey IT Adobe Certified Advanced Coldfusion Developer ~| Upgrade to Adobe ColdFusion MX7 The most significant release in over 10 years. Upgrade see new features. http://www.adobe.com/products/coldfusion?sdid=RVJR Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283314 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: Init method and getters / setters in cfc
Yep, It is a good approach if employed and applied correctly. This e-mail is from Reed Exhibitions (Gateway House, 28 The Quadrant, Richmond, Surrey, TW9 1DN, United Kingdom), a division of Reed Business, Registered in England, Number 678540. It contains information which is confidential and may also be privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of distribution, copying or use of this communication or the information in it is strictly prohibited and may be unlawful. If you have received this communication in error please return it to the sender or call our switchboard on +44 (0) 20 89107910. The opinions expressed within this communication are not necessarily those expressed by Reed Exhibitions. Visit our website at http://www.reedexpo.com -Original Message- From: Ian Skinner To: CF-Talk Sent: Mon Jul 09 21:25:16 2007 Subject: Re: Init method and getters / setters in cfc I would add your component is now completely mutable. A developer can add any data they want which may or may not be a big deal depending on ones thinking on such things and what the component is meant to do. An example that shows this code is going to accept any and all input such as this. aObj.set(myOwnSillyvar,Some really bad data) Ian Ben Nadel wrote: Chris, While I don't know what is *right*, here are the arguments that I have heard against the generic getter/setter: * The CFC is not self documenting. Looking at its functions does not give you any insight into what it can set/get. * Not clear on what should be returned if an invalid get is requested. * It makes extending a component more difficult because the parent component now has to be smarter about where it looks for its data. Take that with a grain of salt ;) .. Ben Nadel Certified Advanced ColdFusion MX7 Developer www.bennadel.com Need ColdFusion Help? www.bennadel.com/ask-ben/ -Original Message- From: Peterson, Chris [mailto:[EMAIL PROTECTED] Sent: Monday, July 09, 2007 3:52 PM To: CF-Talk Subject: Init method and getters / setters in cfc A lot of cfc's using init and 'good' OO practices have functions like getDSN(), setDSN('Blah') littered throughout. Can I ask any guru out there why you wouldn't use simple get('keyname') and set('keyname','keyvalue') like the following? cffunction name=get access=public output=no returntype=any cfargument name=name required=true type=string cfreturn evaluate('variables.' arguments.name) / /cffunction cffunction name=set access=public output=no returntype=void cfargument name=name required=true type=string cfargument name=value required=true type=any cfset variables[arguments.name] = arguments.value / /cffunction Then instead of littering your cfc with numerous getters / setter, you have 2 methods that should be able to handle simple or complex values without any problems with much less code. Chris Peterson Gainey IT Adobe Certified Advanced Coldfusion Developer ~| Macromedia ColdFusion MX7 Upgrade to MX7 experience time-saving features, more productivity. http://www.adobe.com/products/coldfusion?sdid=RVJW Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283324 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: Init method and getters / setters in cfc
Somebody (Peter Bell, I think?) has a comprehensive solution involving lists of properties where on a per-property basis you can define whether it is gettable or settable for each access type (i.e. public, private, package), and on a per-class basis you define whether properties are addable and what happens when a non-existent property is accessed. This is non-trivial and gets around the infinitely mutable object problem, and the self-documentation issue. The naked get(key, value), set(key, value) (maybe simplified for use as an example?) is really just a way to expose the variables scope to the world. I wouldn't want to do that in most cases, and if I was really doing a quick and dirty hack I'd just use the this scope and save myself the trouble of even writing the generic get/set. Jaime Metcher -Original Message- From: Ian Skinner [mailto:[EMAIL PROTECTED] Sent: Tuesday, 10 July 2007 6:25 AM To: CF-Talk Subject: Re: Init method and getters / setters in cfc I would add your component is now completely mutable. A developer can add any data they want which may or may not be a big deal depending on ones thinking on such things and what the component is meant to do. An example that shows this code is going to accept any and all input such as this. aObj.set(myOwnSillyvar,Some really bad data) Ian Ben Nadel wrote: Chris, While I don't know what is *right*, here are the arguments that I have heard against the generic getter/setter: * The CFC is not self documenting. Looking at its functions does not give you any insight into what it can set/get. * Not clear on what should be returned if an invalid get is requested. * It makes extending a component more difficult because the parent component now has to be smarter about where it looks for its data. Take that with a grain of salt ;) .. Ben Nadel Certified Advanced ColdFusion MX7 Developer www.bennadel.com Need ColdFusion Help? www.bennadel.com/ask-ben/ -Original Message- From: Peterson, Chris [mailto:[EMAIL PROTECTED] Sent: Monday, July 09, 2007 3:52 PM To: CF-Talk Subject: Init method and getters / setters in cfc A lot of cfc's using init and 'good' OO practices have functions like getDSN(), setDSN('Blah') littered throughout. Can I ask any guru out there why you wouldn't use simple get('keyname') and set('keyname','keyvalue') like the following? cffunction name=get access=public output=no returntype=any cfargument name=name required=true type=string cfreturn evaluate('variables.' arguments.name) / /cffunction cffunction name=set access=public output=no returntype=void cfargument name=name required=true type=string cfargument name=value required=true type=any cfset variables[arguments.name] = arguments.value / /cffunction Then instead of littering your cfc with numerous getters / setter, you have 2 methods that should be able to handle simple or complex values without any problems with much less code. Chris Peterson Gainey IT Adobe Certified Advanced Coldfusion Developer ~| Deploy Web Applications Quickly across the enterprise with ColdFusion MX7 Flex 2 Free Trial http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJU Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283335 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Init method and getters / setters in cfc
It's so trivial to generate the code for getters and setters that I don't really see the point in having generic getters and setters like this. As Ben says, you lose the API for your component. You have no type checking (if that's your thing). You lose the ability to seamlessly change the getter or setter later if the need arises. And if you want to use ColdSpring to inject dependencies, you're either out of luck, or almost as bad, you have a mixed API where some properties have their own setters and others use the generic setter. Also, an aside, there's no reason to use Evaluate() here. Just do cfreturn variables.instance[arguments.name] /. Regards, Brian On 7/9/07, Peterson, Chris [EMAIL PROTECTED] wrote: A lot of cfc's using init and 'good' OO practices have functions like getDSN(), setDSN('Blah') littered throughout. Can I ask any guru out there why you wouldn't use simple get('keyname') and set('keyname','keyvalue') like the following? cffunction name=get access=public output=no returntype=any cfargument name=name required=true type=string cfreturn evaluate('variables.' arguments.name) / /cffunction cffunction name=set access=public output=no returntype=void cfargument name=name required=true type=string cfargument name=value required=true type=any cfset variables[arguments.name] = arguments.value / /cffunction Then instead of littering your cfc with numerous getters / setter, you have 2 methods that should be able to handle simple or complex values without any problems with much less code. Chris Peterson Gainey IT Adobe Certified Advanced Coldfusion Developer ~| Create Web Applications With ColdFusion MX7 Flex 2. Build powerful, scalable RIAs. Free Trial http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJS Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283340 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4