In the first extraction of the HipsterCollection class (PDF page 84), it “extends IterableBase”. When the class is further made abstract (again PDF page 84), it “implements Collection”. In the third iteration of HipsterCollection (PDF page 85), again it “extends IterableBase”. There is no mention of why this back and forth is happening. Is this just a typo or is there reasoning behind it?
That’s mostly a typo.
Implementing Collection was the old way of doing it (pre 1.0). It still works (which is why my book unit tests didn’t catch it), but it is not as nice as extending iterable base. Both cases give you a collection-like thing, but implementing Collection means that you have to manually implement around two dozen collection methods. Extending IterableBase gives you those two dozen methods for free as long as you define an iterator method, as was done in the first example.
I actually thought I went through and caught all of these, but it seems that I missed one. Thanks for catching it (we’ll get it updated) and sorry for the confusion.
|You must be logged in to comment|