Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 1.9 KB

735a.md

File metadata and controls

30 lines (23 loc) · 1.9 KB

Back to questions

735a: Generic iterators

Note: If you had trouble with questions 85bb or a6e7 you could uses the sample solutions for those questions as a guide when completing this question.

In questions 85bb and a6e7 you were asked to add the StringStackIterator and IntSetIterator interfaces to your collection of string stack and int set classes, respectively. Your task was then to add an iterator method to the StringStack and IntSet interfaces, and provide implementations of StringStackIterator for each type of string stack (resulting in StringStackArrayIterator and StringStackListIterator) and IntSetIterator for each type of int set (resulting in MemoryEfficientIntSetIterator and SpeedEfficientIntSetIterator) respectively.

Your task is now to do something analogous for the GenericStack and GenericSet interfaces and implementing classes that you have defined in question b401. This should be a straightforward case of cutting and pasting the iterators from question 85bb/a6e7 (either from your solution or the sample solution) and changing the definitions to be generic, rather than string/integer specific.

This should lead to the generic interfaces GenericStackIterator and GenericSetIterator, together with four implementing classes: one for each of the kinds of stack and set.

You should find that the GenericStackIterator and GenericSetIterator interfaces are identical. Improve your design to eliminate this duplication by replacing these interfaces with a single GenericIterator interface.

Extension: Interfaces GenericStack and GenericSet have the common method iterator(). Abstract this duplication by creating a unifying interface, GenericCollection, that offers the iterator() method, and make GenericStack and GenericSet both extend your new interface.