I think you hit the nail on the head as to why that might be a bad idea--it all just depends on how controlled your environment really is. If you have lots of control and are pretty sure Bad Stuff(tm) won't be going on, then this probably is an OK approach and might mean less work/more flexibility, at the cost of a bit of safety. Just have to weigh the pros and cons.
Matt On Wed, 23 Mar 2005 14:54:11 -0600, Knipp, Eric <[EMAIL PROTECTED]> wrote: > For a project we are about to start working on, there is a need for several > different types of bean collections. > > The question I am trying to figure out .. is it okay to create a 'generic' > collection and use it for this? It will require me to use returntype and > parameter type of "any" for anything having to do with the beans it > interacts with. The alternative is to create a custom collection class for > each one. In that case I would probably just create a base class and > override the item() and add() methods of my component .. no reason I > couldn't continue to use the existing count() and remove() methods as they > don't return any objects. > > My 'generic' class would look just like this: > > <cfcomponent displayname="collection"> > <cfset variables.instance = StructNew() /> > <cfset variables.instance.items = ArrayNew(1) /> > > <cffunction name="init" access="public" returntype="collection"> > <cfset variables.instance = StructNew() /> > <cfset variables.instance.items = ArrayNew(1) /> > <cfreturn this /> > </cffunction> > > <cffunction name="add" access="public" returntype="any"> > <cfargument name="item" type="any" required="true"> > <cfset ArrayAppend(variables.instance.items, arguments.item) > /> > <cfreturn arguments.item /> > </cffunction> > > <cffunction name="item" access="public" returntype="any"> > <cfargument name="index" type="numeric" required="true"> > <cfreturn variables.instance.items[arguments.index] /> > </cffunction> > > <cffunction name="count" access="public" returntype="numeric"> > <cfreturn ArrayLen(variables.instance.items) /> > </cffunction> > > <cffunction name="snapShot" access="public" returntype="void"> > <cfdump var="#variables.instance#" /> > </cffunction> > </cfcomponent> > > The 'custom' versions would be real similar, just overriding the add and > item functions as I mentioned above. Is there any reason this is a bad > idea, other than the obvious fact that consumers of the component will be > able to pass in all sorts of crap other than objects into the collection (I > would expect them to know better)? > > Thanks > > Eric > > ----------------------------------------- > CONFIDENTIALITY NOTICE: The information contained in this e-mail and > attached document(s) may contain confidential information that is intended > only for the addressee(s). If you are not the intended recipient, you are > hereby advised that any disclosure, copying, distribution or the taking of > any action in reliance upon the information is prohibited. If you have > received this e-mail in error, please immediately notify the sender and > delete it from your system. > > ---------------------------------------------------------- > To post, send email to [email protected] > To unsubscribe: > http://www.dfwcfug.org/form_MemberUnsubscribe.cfm > To subscribe: > http://www.dfwcfug.org/form_MemberRegistration.cfm > > -- Matt Woodward [EMAIL PROTECTED] http://www.mattwoodward.com ---------------------------------------------------------- To post, send email to [email protected] To unsubscribe: http://www.dfwcfug.org/form_MemberUnsubscribe.cfm To subscribe: http://www.dfwcfug.org/form_MemberRegistration.cfm
