Iterator (Chapter 28)

SOLUTION 28.1A working program is:
package com.oozinoz.applications;
import com.oozinoz.fireworks.*;
public class ShowFireworkList
{
    public static void main(String[] args)
    {
        FireworkList flist =
            Promo.getPromotionalFireworks();
        FireworkList.Itr i = flist.iterator();
        
        while (i.hasNext())
        {
            Firework f = i.next();
            System.out.println(
                f.getName()
                    + ", $" + f.getPrice()
                    + ", "  + f.getType());
        }
    }
}
SOLUTION 28.2As Chapter 16, Factory Method, describes, iterators provide a classic example of the FACTORY METHOD pattern. A client that wants an iterator for an instance of a ProcessComponent knows when to create the iterator, but the receiving class knows which class to instantiate.
SOLUTION 28.3You need to change the next() code ...

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.