DESIGN PATTERN #8: ITERATOR

class Printer {
	static void printAll(Enumeration e) {
		while(e.hasMoreElements()) {
			System.out.println(e.nextElement().toString());
		}
	}
}

class LabirintoDeRatos {
	public static void main(String[] args) {
		Vector ratos = new Vector();
		for(int i = 0; i < 3; i++ ) {
			ratos.addElement(new Rato(i));
		}
		Printer.printAll(ratos.elements()); // iterador criado aqui
	}
}
public Enumeration elements() {
	return new Enumeration() {
		int count = 0;

		public boolean hasMoreElements() {
			return count < elementCount;
		}

		public Object nextElement() {
			synchronized (Vector.this) {
				if (count < elementCount) {
					return elementData[count++];
				}
			}
			throw new NoSuchElementException("VectorEnumeration");
		}
	};
}