COM1204 Summer Quiz #1 Version A- Prof. Futrelle

Quiz #1 - Thursday 3 July - Closed book/notes


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

Question 1: You are given the following test program for reference:


class TestDogs {
	public static void main(String[] args) {
		Kennel kennelA = new KennelA();
		Kennel kennelB = new KennelB();
		Barker dogA = kennelA.getADog();
		Barker dogB = kennelB.getADog();
		System.out.println(dogA.speak() + " " + dogB.speak());
	}
	// Output of the above is: "WOOOF! yip"
}

You are to write the following code, all with public access. (Hint: The classes in which methods are implmented are related to the corresponding interfaces.)

The hallmarks of the Factory Method are that an operation:

Using careful technical terms, discuss the above three points as they apply to the method getADog(). As part of this explain why dogA.speak() and dogB.speak() return distinct results. Hint: Discuss the apparent and actual types of dogA and dogB.

Question 2: The general structure of the Observer pattern as specified in your textbook, and some specifics of the "Gossip" example I have previously given you are paired below. Your job is to explain the correspondence in each pair.