Factory Methods
- Every collection can produce an iterator
Iterator iter = list.iterator()
- Why not use constructors?
Iterator iter = new LinkedListIterator(list);
- Drawback: not generic
Collection coll = ...;
Iterator iter = new ???(coll);
- Factory method works for all collections
Iterator iter = coll.iterator();
- Polymorphism!