COM1204 Summer Midterm Exam Version B
Prof. Futrelle

Monday 28 July - Closed book/notes


Be sure to write complete information in your blue exam book: Name, course, date, exam version B.

Question 1: A Pattern You are to write out three class definitions and one interface definition, as Java code. You needn't specify any access priviliges (default package access) unless your use of an interface requires public access. In the description below, be sure you understand that another, text and your are the names of fields; they are the names of variable fields in their classes. The four methods discussed below are each of type void. The design in this question is an example of the Adapter Design Pattern.

The ClientsInterface interface specifies the method service().
The YourImplementation class implements the ClientsInterface and extends a class ExistingClass.
The ExistingClass class has a field, another, of type AnotherClass. It also has a method, usefulMethod(), which calls helper() on its instance of AnotherClass.
YourImplementation defines a method service() that calls usefulMethod(). This is an important point. service() does nothing itself except call another method.
AnotherClass is an auxilliary class that contains a String field, text, which is initialized to "I'm a helper.".
AnotherClass has a helper() method that prints the text variable to stdout.
The main() method in YourImplementation creates an instance of YourImplementation and assigns it to a field your.
The main() method then sets the another field of your to an instance of AnotherClass it creates.
The main() method finally calls the service() method on its your field.

Question 2: Seeing Patterns For the classes defined above, draw the corresponding (static) UML diagram for the classes and interface. Then draw the corresponding sequence diagram.

Question 3: What is this Pattern Explain why the previous example is an example of the Adapter Design Pattern. Describe both the Object Adapter and Class Adapter patterns and explain which one is used in the example above.

HINT: A client normally expects to use service(). But the the system described here implements service() so that it ends up using some already existing functionality. Is the access to this other functionality via subclassing or by creating an object that has the functionality needed? That's the sort of question you have to ask yourself.