CS510 Design Patterns, Winter 00, Final, March 13
Name: ______________________
This is an individual, closed-book exam.
There are 6 problems.
You have 75 minutes to complete this exam.
If a problem asks for an example or a fragment of code,
please, answer with the simplest example or fragment of code
you can think of.
If a problem asks for a Yes/No or similar answer, please
make sure that your solution provides this answer.
If you feel that you need to make additional assumptions
for the solution of a problem, please state the assumptions
you make.
- 1.
-
What is the name of the pattern intended
to prevent concurrent access to data?
Sketch the code/structure of this pattern.
- 2.
-
The Singleton Pattern relies on two key Java constructs
or features to ensure that:
(1) at most only one object of a class is ever created by clients, and
(2) a reference to the unique instance of the singleton class is always accessible to clients.
Name and briefly explain these features.
Sketch the code/structure of this pattern.
- 3.
-
A command of a Command Pattern, say SetCurrentClock,
is intended to set the current time within an application program.
Discuss the key elements of a class that implements
the SetCurrentClock command and sketch its code.
Hint: you can assume the existence of any time manipulation
method that you need. Use an expressive enough name for any
such method and/or describe with a comment or separately what the method does.
Sketch the code/structure of the SetCurrentClock class.
- 4.
-
The Factory Method Pattern is used to construct
families of related objects. This pattern relies on a key
property of Object Oriented Programming Languages and
Java in particular.
Describe this property and how it enables the pattern
to construct different objects. Hint: In your answer,
I am looking for a clear, complete and concise explanation.
I do not want to read code.
- 5.
-
The Visitor Pattern relies on both overloading
and overriding of methods. Briefly define these concepts and use
a minimal abstract example to clarify your statements or definitions.
I am not asking for a description or an example of an actual visitor.
What are the conventional names and signatures of the overloaded
and overridden methods in the Visitor Pattern.
- 6.
-
For each question check zero or more choices according to the directions.
- (a)
-
A not-yet-loaded Java class is loaded when (check the most accurate choice):
-
- A constructor is invoked.
-
- A static member is referenced.
-
- Both of the above choices.
-
- All of the above choices and in additional situations.
- (b)
-
The equals method in class java.lang.Object
(check all the correct choices):
-
- Takes two arguments to compare.
-
- Can be overridden in subclasses.
-
- Tests whether two references refer to the same object.
-
- Tests whether two references refer to objects with the same value.
- (c)
-
Enumeration in package java.util identifies
(check all the correct choices):
-
- An interface.
-
- An abstract class.
-
- A (concrete) class.
-
- None of the above choices.
- (d)
-
The Prototype Pattern creates new objects by
(check the most accurate choice):
-
- Shallow copying.
-
- Deep copying.
-
- An appropriate combination of both the above choices.
-
- Invoking either method clone or a ``copy constructor.''
- (e)
-
The ``extrinsic state'' of a Flyweight object is
(check all the correct choices):
-
- Information shared by all the Flyweight objects.
-
- Information shared by some Flyweight objects.
-
- Information shared by no Flyweight objects.
-
- Information stored by clients of Flyweight objects.