Please State and Sign
your Pledge:
1a) 10 |
1b) 5 |
1c) 5 |
2a) 15 |
2b) 10 |
3a) 10 |
3b) 15 |
3c) 15 |
4a) 10 |
4b) 5 |
TOTAL 100 |
|
|
|
|
|
|
|
|
|
|
|
1. Design an object model for the following immutable data structure that represents a web page (20 pts total):
You will need to:
a) Draw the corresponding UML class diagrams. (10 pts)
b)
Identify the design patterns in your design. (5 pts)
c) Justify the use of any abstract classes in your design. (5 pts)
2. Consider the following UML class diagram for generalized
lists (lists that may contain lists), as seen in homework #2. (25 pts total)
a)
Suppose you are given an AGenList,
gls, that contains String and/or lists of String. Add appropriate
methods and write the code to locate a given String,
w, and return an AtomicGList whose first is w
(the search order is unimportant). If w cannot be found,
then return null. Use the String
method equals() for String equality. You do not have to write out the code for the whole class, just
indicate to which class your methods belong.
Write on the back of the page if you run out of space. (15 pts)
b)
Explain what you need to do to apply the visitor pattern to
the above structure. (10 pts)
Be specific as to exactly
· What classes and/or interfaces you need to add.
· What methods are added to what classes/interfaces.
·
What the signatures of those methods are.
3. For this problem, you are to use the familiar immutable list framework, IList, given by the following UML diagrams. (40 pts)
In the above diagram the interface ILambda is a model of an abstract function that can take an Object as input and produce some Object as output via the apply method, which has an argument, arg.
a) Give an example of (i.e. write the code for) a concrete ILambda that takes Integer as input and returns a Boolean as output. Such an ILambda is called a predicate on the Integer. (10 pts)
b) Write a visitor called Map that takes as input an ILambda and returns an IList consisting of applying the ILambda to each element in the IList host. (15 pts)
c) Write a visitor called Filter that takes as input an ILambda predicate and when executed by an IList host, “h”, returns an IList consisting only of elements in “h” for which the input ILambda predicate holds true. (15 pts)