OrigionalIterator and DecoratorInterator should share the same interface.
PHP Code:
interface MyAbtractIterator {
public function next();
public function hasNext();
public function reset();
}
PHP Code:
OrigionalIterator implements MyAbtractIterator {
public function __construct($result) { ... }
public function next() { ... }
public function hasNext() { ... }
public function reset() { ... }
}
PHP Code:
DecoratorIterator implements MyAbtractIterator {
protected $iterator;
public function __construct(MyAbtractIterator $iterator) {
$this->iterator = $iterator;
}
public function next() {
// change behavior here
return $this->iterator->next();
}
public function hasNext() {
// change behavior here
return $this->iterator->hasNext();
}
public function reset() {
// change behavior here
return $this->iterator->reset();
}
}
Bookmarks