Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

The iterator pattern is very clearly defined. What would you call the consumer of an iterator?

share|improve this question

closed as not constructive by Glenn Nelson, MichaelT, World Engineer, Dynamic, gnat Feb 20 '13 at 7:13

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
The first thing that pops into my head is "an aggregator." –  Erik Dietrich Feb 19 '13 at 18:16
    
@ErikDietrich please make that an actual answer. –  user7550 Feb 19 '13 at 18:58
1  
I believe aggregator implies that what you are doing with the iterable is aggregating it, which isn't always true. –  psr Feb 19 '13 at 19:02

5 Answers 5

up vote 0 down vote accepted

My comment was to say that I'd call the class an "aggregator," and I'm putting it here as requested. I'd also like to respond to the comment suggesting that the results aren't always aggregated, presumably in the sense of totaling up some kind of value.

What I mean with "aggregate" is the qualitative dictionary definition of the term: "taking all units as a whole." This doesn't necessarily mean that each record has some integer property and the total of that property is the aggregate. Rather, I'd consider the "aggregate" to be the interpretation of the the big picture. You're considering a sequence of these things as part of some larger gestalt (i.e. "as a whole," in whatever sense that means to you.)

share|improve this answer
    
I agree with the usage of aggregator, even if this isn't doing SUM or COUNT, it's still applying an operation across the aggregation of all of the data. –  user7550 Feb 19 '13 at 19:58
    
Certainly all the functions of that category in SQL (AVG, MIN, etc.) are called aggregators. –  Malvolio Feb 19 '13 at 20:36

One reason you may need to ask is that the original Gang of Four book describing the iterator pattern refers to the consumer of an iterator with the highly distinctive name of "client" (and in fact later on it doesn't show the client as one of the participants in the pattern at all).

I don't know of any specific jargon for the consumer of an iterator, and would guess that no standard name has been settled on.

Iteratoror comes to mind, but I don't expect it to catch on.

share|improve this answer

You just said it - the consumer of an iterator (or the client). :) This is the language used in this reference and elsewhere.

In agreement with Erik's answer, the way to name the consumer (IMO) is to imply iteration with a term like aggregate / sum / iterate or even just use a plural (e.g. GetCustomers). Yet describing its business purpose is probably more important than calling out the fact that it is iterating (again IMO).

share|improve this answer
1  
"FooMyIteratorConsumer" doesn't seem very optimal. It is explicit however. –  user7550 Feb 19 '13 at 19:04
    
Ah, now I understand exactly why you were asking. I've updated my answer to try to help. –  Dave Clausen Feb 19 '13 at 20:50
    
The business purpose is the iteration, hence the question. –  user7550 Feb 19 '13 at 20:56

Iterable. An Iterable uses an Iterator to iterate its elements. Hence it is consuming the iterator .

share|improve this answer
    
I think he means the class calling the iterator to iterate the iterable's elements. –  psr Feb 19 '13 at 18:43
    
@psr then he should make the question explicit . –  Geek Feb 19 '13 at 18:44
    
+1 on this, i wasn't asking specifically for this but I had another class that this was directly relevant for. Renamed DocumentsProvider to DocumentsIterable. I didn't want to call it DocumentsIterator because you needed to do foreach(documentsIterable.AllDocuments) not foreach(DocumentsIterator) –  user7550 Feb 19 '13 at 19:17

Despite that "aggregator", "IteratorClient" & "IteratorConsumer" seems to match the idea, I suggest to "highlight" the goal of your class, as your class identifier.

.............................
..+-----------------------+..
..|     ArrayListClass    |..
..+------*----------------+..
.........*...................
..........*..................
...........*.................
............*................
............*................
..+----------*--------+......
..|                   /......
..| Has Iterators    /.......
..|                 / |......
..+----------------/--+......
.............................

One exception, that I have to deal with, is that you have a class, without iterators, and you make a subclass, with the only goal of adding iterators, and you cannot or do not want to add the iterators to the original class.

.............................
..+-----------------------+..
..|     TreeViewClass     |..
..+-----------*-----------+..
..............|..............
..............|..............
..............|..............
..............^..............
............./.\.............
............/...\............
.........../--*--\........... 
..............|..............
..............|..............
..............|..............
..+-----------*-----------+..
..| IterableTreeViewClass |..
..+-----------------------+..
.............................

Cheers

share|improve this answer
1  
As I commented on another answer, the actual business purpose of the class is the execution of the iteration itself. Using your examples it would fundamentally be TreeViewAggregator –  user7550 Feb 19 '13 at 22:01
1  
@Chris Marisic : Agree, but, the "aggregator" word seems weird to me. –  umlcat Feb 19 '13 at 22:22