diff --git a/questions/85bb.md b/questions/85bb.md index cef50a4..7919f11 100644 --- a/questions/85bb.md +++ b/questions/85bb.md @@ -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 @@ -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.