ClassA myA = new ClassA();
// add some items
//...
//...
// now iterate over the collection:
for( ClassB nextB : myA ) {
// do something with nextB
}
If ClassA were not to implement the Iterable<ClassB> interface, we would not be able to use a for-each loop to iterate over the collection.
We saw an example of this in lecture. The RemoteControl class implemented the Iterable<Channel> interface and this allowed us to use a for-each loop to iterate over the collection of Channel objects stored in the RemoteControl.
Paul
PaymentHistory myPaymentHistory = new PaymentHistory();
//...
// add some payments to myPaymentHistory
//...
// now iterate over the payments in the PaymentHistory...
for( Payment next : myPaymentHistory ) {
// process next payment
}
So think about how you modify the design of PaymentHistory below so that the client code above will work.
Paul
Paul