should an vigilant exercise an iterator enclose another vigilant implements an iterator
i'm perplexing conduct around spl iterators i've adult 2 ways hoop it. i initial chronicle reduction difficult nonetheless second chronicle multiple feel (i think).
what am i observant preferable over other? am i only over complicating this?
here thoughts:
the vigilant implements an iterator:
class boxofchocolates implements iterator {
private $id
private $name; // e.g. valentine's heart box
private $maker; // e.g. hersheys
private $items; // array
open duty getchocolates() {
$query = ...
foreach($rows $row) {
$this->_items[] = new chocolate() ...
}
}
// ... required iterator doing stuff
}
the vigilant contains an iterate-able object:
class boxofchocolates {
private $id;
private $name;
private $maker;
private $items; // chocolates object
open duty getchocolates() {
$this->items = new chocolates();
$this->items->getchocolates();
}
}
class chocolates implements iterator {
private $items;
open duty getchocolates() {
$query = ...
foreach($rows $row) {
$this->_items[] = new chocolate() ...
}
}
// ... required iterator doing stuff
}
Comments
Post a Comment