Hi,
I've thought about both these options, but just can't decide on which to go with and why. i.e. what are the drawbacks or advantages of choosing one over the other.
Please see this code. The Feed object implements an iterator to cycle through a list of feeds.
This is via a Class method
use Feed; while (my $feed = Feed->next) { $feed->fetch(); }
Here, the next method implements an iterator and returns a new Feed object. The first time the next method is called, it may need to do some initializing stuff, like maybe connecting to a database.
This is using an object method
use Feed; my $feed = Feed->new; while ($feed->set_next) { $feed->fetch; }
In this case, I use the new method to initialize and create a Feed object. The set_next method cycles through the list of feeds, and sets variables of the current Feed object. What I like about this option, is that the new method is separate from the Iterator.
Any criticisms of a particular choice?
Thanks!
In reply to Iterator as a Class or Object Method by arc_of_descent
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |