Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions questions/85bb.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ You should now find that `StringStackArray` and `StringStackList` no
longer compile. This is because they do not implement the `iterator` method.

### Step 3
In order to fix this, you need to create two new classes: `StringStackArray``Iterator`,
In order to fix this, you need to create two new classes: `StringStackArrayIterator`,
and `StringStackListIterator`. Both classes should implement the `StringStackIterator`
interface. Writing these classes is a little tricky, but once you have them, implementing
the `iterator` method in `StringStackArray` is straightforward: simply
Expand All @@ -64,7 +64,7 @@ return a new `StringStackArrayIterator`; implementing `iterator` in

So, how should you implement the iterator classes? There are two choices:

1. Create a fresh class for each of `StringStackArrayIterator` and `StringStack``ListIterator`.
1. Create a fresh class for each of `StringStackArrayIterator` and `StringStackListIterator`.
Let us consider the `StringStackArrayIterator` case.

`StringStackArrayIterator` should have a field of type `String[]`: a reference to the contents of the stack. In addition, this class should have a field of type `int` that refers to the stack element that the iterator is currently pointing to. This should be initialised to the top of the stack. This solution is OK, but it requires the internal details of a `StringStackArray` to be indirectly exposed to the separate `StringStackArrayIterator` class, since a `StringStackArrayIterator` is constructed using the internals of a `StringStackArray`. More importantly, this setup allows clients to construct instances of `StringStackArrayIterator` *independently* of any actual `StringStackArray`. This doesn't really make sense. The extent of this problem can be limited by making the `StringStackArrayIterator` only package visible.
Expand Down