UMBC  |  CSEE  |  Tarr  |  CS491D

CMSC491D Design Patterns In Java

Fall 2000

Final Sample Test Questions


1) What pattern allows you to use an existing class when its interface does not match the one you need?

2) Which design pattern is illustrated by the implementation of the Java I/O classes?

3) Both the Observer and the Chain of Responsibility patterns attempt to decouple sending and receiving objects. Compare these two patterns with regard to such decoupling.

4) To improve web page download times, a designer thinks it would be a good idea to have the browser pre-fetch all of the pages referenced from the page the user is currently viewing. But rather than have each individual client pre-fetch the pages from remote web servers, it would be even better if all the pre-fetched pages for a group of clients could be made available locally.

Select the most appropriate design pattern to use to address the problem and show how it is applied. In particular, show an appropriate class diagram(s) and enough code fragments to illustrate your use of the pattern to solve the problem.

5) We are writing the software for a new electronic hand dryer. The dryer has a light sensor which can determine whenever someone's hands are placed under it. This triggers the dryer to start blowing hot air. The dryer can also be triggered via a push button on the unit. Once the unit starts blowing, we do not want additional pushes of the button or triggers of the light sensor to extend the air blowing cycle.

Select the most appropriate design pattern to use to address the problem and show how it is applied. In particular, show an appropriate class diagram(s) and enough code fragments to illustrate your use of the pattern to solve the problem.

6) Company X has a large amount of applications software written using a particular class library. Company Y that wrote the class library has now gone out of business. Company X buys a new class library from Company Z that provides the same functionality as the previous library, but unfortunately many of the classes have different interfaces. Company X does not have access to the source code for the old or the new library. What should Company X do??

Select the most appropriate design pattern to use to address the problem and show how it is applied. In particular, show an appropriate class diagram(s) and enough code fragments to illustrate your use of the pattern to solve the problem.

7) The designer of an adventure game wants a player to be able take (and drop) various items found in the rooms of the game. Two of the items found in the game are bags and boxes. Both bags and boxes can contain individual items as well as other bags and boxes. Bags and boxes can be opened and closed and items can be added to or taken from a bag or box.

Select the most appropriate design pattern to use to address the problem and show how it is applied. In particular, show an appropriate class diagram(s) and enough code fragments to illustrate your use of the pattern to solve the problem.


Bob Tarr
University of Maryland, Baltimore County
tarr@umbc.edu
UMBC  |  CSEE  |  Tarr  |  CS491D