Docsity

Object-Oriented Design & Patterns: Chapter 5 Questions and Answers - Prof. Paul C. Grabow, Assignments of Software Engineering

Toggle sidebar
bg1
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?

Partial preview of the text

Download Object-Oriented Design & Patterns: Chapter 5 Questions and Answers - Prof. Paul C. Grabow and more Assignments Software Engineering in PDF only on Docsity!

Object‐Oriented Design & Patterns Chapter 5 Questions Revised 10/29/

  1. Assume that you have a collection of Person objects, i.e., instances of the Person class. In Java, a collection can be represented several different ways, one of which is an ArrayList. Show how you would iterate through an ArrayList, printing out each person, assuming that Person has toString defined.
  2. Assume that you have a Student class with the following attributes: int id, string firstname, and string lastname. Also assume that Student implements the Comparable interface based on the value of id. If you have an ArrayList of Student, show how you would list the students in ascending order using a. Id b. lastname, firstname, i.e., phonebook ordering
  3. Draw the hierarchy of Collection subclasses in Java. Use the index to locate the information.
  4. How is the iterator pattern better than the approach using the direct manipulation of links, e.g., a next pointer within an object?
  5. Explain how the Scanner and InputStream concepts in Java are related to the iterator pattern.
  6. Why are Gamma, Helm, Johnson and Vlissides mentioned in chapter 5? What name is often associated with them?
  7. What is the relationship between the model/view/controller architecture and the observer pattern?
  8. List the various layout managers that Java provides.
  9. Show the relationship between Java layout managers and the strategy pattern using class diagrams.
  10. What design pattern is related to the use of the Java Comparator interface?
  11. For the Composite pattern, describe when/why it would be used and describe the solution (using a class diagram).
  12. What pattern does a JScrollPane implement?
  13. How is the Composite pattern similar to the Decorator pattern with respect to the use of an interface that contains an abstract method?
  14. What design pattern does the set of Java stream filters implement?
  15. What method does JScrollPane implement that is related to the abstract method (in the interface) that is part of the Component pattern?
  16. What design pattern is related to the various reader classes?