Saving all changed workpiece objects by querying then saving them.

Patterns in Java
Collections for States
Kevlin Henney
Listing 2. Saving all changed workpiece objects by querying then saving them.


public class Application
{
    public void saveChanges()
    {
        Iterator workpiece = changed.iterator();
        while(workpiece.hasNext())
        {
            Workpiece current = (Workpiece) workpiece.next();
            if(!current.saved())
                current.save();
        }
    }
    ...
    private Collection workpieces;
}

About the Author

Kevlin Henney is a Principal Technologist with QA Training in the UK.