mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-12 09:54:09 +02:00
Behavioral\Iterator restructured
This commit is contained in:
23
Behavioral/Iterator/BookListReverseIterator.php
Normal file
23
Behavioral/Iterator/BookListReverseIterator.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Behavioral\Iterator;
|
||||
|
||||
class BookListReverseIterator extends BookListIterator
|
||||
{
|
||||
|
||||
public function __construct(BookList $bookList)
|
||||
{
|
||||
$this->bookList = $bookList;
|
||||
$this->currentBook = $this->bookList->count() - 1;
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
$this->currentBook--;
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return 0 <= $this->currentBook;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user