Advance Object Oriented Design Programming - Midterm Exam | CS 635, Exams of Computer Science

Material Type: Exam; Professor: Whitney; Class: ADV OBJ ORIENT DSGN PROG; Subject: Computer Science; University: San Diego State University; Term: Spring 2009;

Typology: Exams

Pre 2010

Uploaded on 03/28/2010

koofers-user-yzp-1
koofers-user-yzp-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name __________________________________________
Answer 9 of the following questions. Indicate which of the questions you wish to be graded. Answer
essay questions as briefly as possible.
1. Assume we have a method called trimBlanks() on the String class that removes all leading and
trailing spaces. That is it repeatedly removes the first character of the string as long as it is a
space and repeatedly removes the last character of the string as long as it is a space. Write XUnit
(where X = J, R, S, Cpp) test(s) for the method. C++ people can assume that all C++ strings are
an instance of the String class.
2. The following methods are from classes B & C that have a common superclass A. Rewrite the
methods using the Template method. Show all the methods you would create and which classes
they would be in.
Class B
Key keyFrom(HttpRequest aRequest) {
if (aRequest.identifier().size() < depth() ) {
if (aRequest.hasPostDataAt( "Command"))
return aRequest.postDataAt("Command");
else
return defaultKey();
}
if (containsAction(matchingElement(aRequest)) {
aRequest.decodeFormData();
}
return matchingElement(aRequest);
}
Class C
Key keyFrom(HttpRequest aRequest) {
if (aRequest.identifier().size() < depth() ) {
return defaultKey();
}
return matchingElement(aRequest);
}
3. Explain
A. Information Hiding
B. Encapsulation
C. Abstraction
4. We now have three different ways to produce a list of all odd valued integers in a linked list. Select
two of the methods and discuss the pros and cons of each way.
5. In object-oriented programming programers are told to avoid if (case) statements and replace
them with polymorphism. What is gained by using polymorphism and what is lost by using poly-
morphism.
5/14/09!CS 635 Midterm!Page 1 of 2
pf2

Partial preview of the text

Download Advance Object Oriented Design Programming - Midterm Exam | CS 635 and more Exams Computer Science in PDF only on Docsity!

Name __________________________________________ Answer 9 of the following questions. Indicate which of the questions you wish to be graded. Answer essay questions as briefly as possible.

  1. Assume we have a method called trimBlanks() on the String class that removes all leading and trailing spaces. That is it repeatedly removes the first character of the string as long as it is a space and repeatedly removes the last character of the string as long as it is a space. Write XUnit (where X = J, R, S, Cpp) test(s) for the method. C++ people can assume that all C++ strings are an instance of the String class.
  2. The following methods are from classes B & C that have a common superclass A. Rewrite the methods using the Template method. Show all the methods you would create and which classes they would be in. Class B Key keyFrom(HttpRequest aRequest) { if (aRequest.identifier().size() < depth() ) { if (aRequest.hasPostDataAt( "Command")) return aRequest.postDataAt("Command"); else return defaultKey(); } if (containsAction(matchingElement(aRequest)) { aRequest.decodeFormData(); } return matchingElement(aRequest); } Class C Key keyFrom(HttpRequest aRequest) { if (aRequest.identifier().size() < depth() ) { return defaultKey(); } return matchingElement(aRequest); }
  3. Explain A. Information Hiding B. Encapsulation C. Abstraction
  4. We now have three different ways to produce a list of all odd valued integers in a linked list. Select two of the methods and discuss the pros and cons of each way.
  5. In object-oriented programming programers are told to avoid if (case) statements and replace them with polymorphism. What is gained by using polymorphism and what is lost by using poly- morphism. 5/14/09 CS 635 Midterm Page 1 of 2
  1. Sometimes one needs to modify a class but for some reason are not allowed to alter the class. What design pattern can be used in this situation? Explain how it can be used.
  2. Explain one of the following types of coupling: Data Coupling, Control Coupling, Inside Internal Object Coupling.
  3. Explain one of the following types of cohesion: Logical, Temporal, Procedural, Communication, Sequential. Give an example.
  4. One issue in the composite pattern is who should declare the child management operations: the Composite or the Component classes. What are the trade-offs involved in deciding where to de- clare the child management operations.
  5. Using iterators to traverse a collection is considered good. In the code given below using the itera- tor takes more lines of code to accomplish the same task. Explain how using the iterator is better than the other solution. var numbers = new LinkedList(); code to add numbers Iterator list = numbers.iterator(); while ( list.hasNext() ) { Integer a = (Integer) list.next(); int b = a.intValue(); if ((b % 2) == 0) System.out.println( x ); } var numbers = new LinkedList(); code to add numbers for (int k =0; k < numbers.size(); k++ ) { Integer a = (Integer) numbers.get(k); int b = a.intValue(); if ((b % 2) == 0) System.out.println( x ); }
  6. Explain how the Command pattern works. 5/14/09 CS 635 Midterm Page 2 of 2