12.07.2015 Views

Podsumowanie wzorców projektowych GoF

Podsumowanie wzorców projektowych GoF

Podsumowanie wzorców projektowych GoF

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

note:// This example shows the Concrete Iterator as an inner class.// The Iterator Pattern in <strong>GoF</strong> does allow for multiple types of// iterators for a given list or "Aggregate". This could be// accomplished with multiple Iterators in multiple inner classes.// The createIterator class would then have multiple variations.// This, however, assumes that you will have a limited number of// iterator variants - which is normally the case. If you do want// more flexibility in iterator creation, the iterators should not// be in inner classes, and perhaps some sort factory should be// employed to create them.//private class InnerIterator implements DvdListIterator {private int currentPosition = 0;private InnerIterator() {}public void first() {currentPosition = 0;}public void next() {if (currentPosition < (titleCount)) {++currentPosition;}}public boolean isDone() {if (currentPosition >= (titleCount)) {return true;} else {return false;}}}}public String currentItem() {return titles[currentPosition];}DvdListIteratorpackage pk.dydakt.to.dp.b.gof.iterator;public interface DvdListIterator {public void first();public void next();public boolean isDone();public String currentItem();}Wyjcie na konsoli:10 Things I Hate About YouShakespeare In LoveO (2001)American Pie 2Scotland, PA.Hamlet (2000)10 Things I Hate About You66

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!