I'm not saying that your method is incorrect. I am just looking at a different form of abstraction. In the case of using the Iterator, where does it resides? I assume that is in the collection class. Then the Algorithm and the Iterator are combined into one. But then I think, this is not right. The sole purpose of an Iterator should be traversing (up, down) through the elements of the collection. Then algorithms can be defined that take iterators as an input arguments. Also I feel that Iterators should be objects themselves and contain begin and end methods (maybe even overloading ++ and --)
CollectionX
->begin (Iterator)
CollectionY
->begin (Iterator)
CollectionZ
->begin (Iterator)
->end (Iterator)
ProgressBar
Flowers
Algorithms
- showProgress - Bound to ProgressBar
- growFlowers - Bound to Flowers
code:
...
use CollectionX ;
use CollectionY ;
use Algorithms qw( showProgress, growFlowers ) ;
...
my colX = new CollectionX ;
colX->... ;
while( showProgress(CollectionX->begin) ) {
}
my colY = CollectionY ;
colY->... ;
while( showProgress(colY->begin) ) {
}
my colY = CollectionY ;
colY->... ;
while( growFlowers(colY->begin) ) {
}
With this level of abstraction it is only needed to define iterators for each type of collection, and only one algorithm for each added functionality. Otherwise I would need to create an iterator for each added functionality for each class (in this example 6 iterators instead of 3) and repeat code 3 + 3 times. I'm not going to build examples on this, just too much work right now. But I think the method with the tie shown by hdb makes this possible and that is why I said like it so much. I hope this helped understanding where I am coming from.