Well, after that lengthy discussion, I figured it was only fair if I posted
some code. :)

As I said before, my goal is to create an iterator interface which can be
used with various types of collections. In my case, I have immediate need
for queries and arrays.

So, I built an Iterator base component which does most of the work. I
created two components, QueryIterator and ArrayIterator, which extend the
Iterator component. They each override the init(), size() and
getCollection() methods.

Yes, this is reuse-by-inheritance. However, I think it's appropriate in this
case. But please let me know if you think otherwise.

Despite my stated preference for ADO style iterators, I decided to go with
one more like what I've seen from Java. I figured that would be more
familiar to people on this list and it seems to work better with <cfloop
condition="">.

Along the same lines, I used the method names and terminology from the Java
Iterator and ListIterator interfaces:

  http://java.sun.com/j2se/1.4.2/docs/api/java/util/Iterator.html

  http://java.sun.com/j2se/1.4.2/docs/api/java/util/ListIterator.html

I haven't performance tested these or even tested the functionality very
thoroughly, for that matter. I want to get the interface right first. I have
attached a simple series of tests for basic functionality, though.

Anyway, let me know what you think.

Ben Rogers
http://www.c4.net
v.508.240.0051
f.508.240.0057


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]

Attachment: Iterator.cfc
Description: Binary data

Attachment: QueryIterator.cfc
Description: Binary data

Attachment: queryTest.cfm
Description: Binary data

Attachment: ArrayIterator.cfc
Description: Binary data

Attachment: arrayTest.cfm
Description: Binary data

Reply via email to