
Object‐OrientedDesign&Patterns
Chapter5Questions
Revised10/29/2008
1. AssumethatyouhaveacollectionofPersonobjects,i.e.,instancesofthePersonclass.InJava,a
collectioncanberepresentedseveraldifferentways,oneofwhichisanArrayList.Showhow
youwoulditeratethroughanArrayList,printingouteachperson,assumingthatPersonhas
toStringdefined.
2. AssumethatyouhaveaStudentclasswiththefollowingattributes:intid,stringfirstname,and
stringlastname.AlsoassumethatStudentimplementstheComparableinterfacebasedonthe
valueofid.IfyouhaveanArrayListofStudent,showhowyouwouldlistthestudentsin
ascendingorderusing
a. Id
b. lastname,firstname,i.e.,phonebookordering
3. DrawthehierarchyofCollectionsubclassesinJava.Usetheindextolocatetheinformation.
4. Howistheiteratorpatternbetterthantheapproachusingthedirectmanipulationoflinks,e.g.,
anextpointerwithinanobject?
5. ExplainhowtheScannerandInputStreamconceptsinJavaarerelatedtotheiteratorpattern.
6. WhyareGamma,Helm,JohnsonandVlissidesmentionedinchapter5?Whatnameisoften
associatedwiththem?
7. Whatistherelationshipbetweenthemodel/view/controllerarchitectureandtheobserver
pattern?
8. ListthevariouslayoutmanagersthatJavaprovides.
9. ShowtherelationshipbetweenJavalayoutmanagersandthestrategypatternusingclass
diagrams.
10. WhatdesignpatternisrelatedtotheuseoftheJavaComparatorinterface?
11. FortheCompositepattern,describewhen/whyitwouldbeusedanddescribethesolution
(usingaclassdiagram).
12. WhatpatterndoesaJScrollPaneimplement?
13. HowistheCompositepatternsimilartotheDecoratorpatternwithrespecttotheuseofan
interfacethatcontainsanabstractmethod?
14. WhatdesignpatterndoesthesetofJavastreamfiltersimplement?
15. WhatmethoddoesJScrollPaneimplementthatisrelatedtotheabstractmethod(inthe
interface)thatispartoftheComponentpattern?
16. Whatdesignpatternisrelatedtothevariousreaderclasses?