CSE432 Spring 2006Take-Home Final Exam

Name ______

This examination is to be completed and submitted by each student individually, without assistance from any other person. If you have any questions about whatthe examination is asking, you may send them of Prof. Gill only, via e-mail. If the question is of general interest, Prof. Gill will post clarifying comments to the course newsgroup.

You may cite information that appears in the text books, or in documents submitted by the team in your answers. However, if you do this, (1) you must say from which document each instance of such content came, and (2) you must distinguish it clearlyfrom the partsthat you wrote yourself (and most of the answer should be in your own words), by putting the cited portion in quotation marks, indenting and italicizing it, or using some other reasonable way of making it stand out so it’s clear what portion came from the group document.

This exam is provided in electronic form so that you can complete and submit it either in electronic form or in hard copy. Before you submit your examination, please put your name on the line at the top of this page, and then please also complete the certification at the bottom of this page, stating that you completed the exam on your own without help from any other person.

Certification:______

______

______

______

  1. (16 points) Next to the name of each pattern, please write the letter of the description belowthat best matches it:

____ 1. Abstract Factory Pattern____ 9. Builder Pattern

____ 2. Adapter Pattern____ 10. Bridge Pattern

____ 3. Iterator Pattern____ 11. MementoPattern

____ 4. Factory MethodPattern____ 12. PrototypePattern

____ 5. Command Pattern____ 13. Façade Pattern

____ 6. Decorator Pattern____ 14. Flyweight Pattern

____ 7. Chain of Responsibility Pattern____ 15. Interpreter Pattern

____ 8. Generation Gap Pattern____ 16. State Pattern

A.Take an interface you’re given and turn it into one you want.

B. Gives more than one object the chance to handle a request.

C.Hides subsystems behind a common interface.

D.Uses delegation instead of sub-classing to add functionality.

E. Saves and restores an object’s state without revealing object details.

F. Provide a way to create different families of related classes.

G.A class hierarchy definesand evaluates a language’s abstract syntax.

H. Separates creation of objects from plan for how they’re assembled.

I.Allows many fine-grained objects to be shared efficiently.

J. Subclasses encapsulate modifications to generated code.

K. Move through items in a container, while hiding how they’re stored.

L. Wraps a function (and possibly parameters to it) within an object.

M.Type-preserving copying of objects, that’s invoked polymorphically.

N. Base class method lets subclasses override which class it instantiates.

O. Allow an object to change its behavior when its state changes.

P.Decouples an interface from its implementation.

  1. (8 points) In what ways are the Adapter and Bridge patterns similar?

In what ways are they different?

When would it be better to use Adapter than Bridge?

When would it be better to use Bridge than Adapter?

  1. (8 points) In what ways are the Façade and Mediator patterns similar?

In what ways are they different?

When would it be better to use Façade than Mediator?

When would it be better to use Mediator than Façade?

  1. (8 points) Assume you were designing a program that had the following two design forces:
  1. you needed to be able to undo actions performedon a target object in the program; and
  1. none of the actions has a natural closed form “inverse” action that could undo the previous action (examples of natural closed form inverses include subtraction for addition, division for multiplication, etc.) – instead, it is necessary to restore the state that the target object had prior to the action, explicitly.

Which two GoF design patterns we have studied so far would besthelp to resolve both of these design forces?

How would each of these design patterns resolve those design forces?

What role would the target objectplay in each of these design patterns?

  1. (14 points): In the third chapter of the Pattern Hatching textbook, Vlissides revisits several of the GoF patterns. Please answer the following questions drawn from that material:

a. In “To Kill a Singleton,” what is the argument against having a public destructor for the singleton object?

What is the argument against having a private destructor for the singleton object?

b. In “The Trouble with Observer,” what kinds of redundancy can appear at run-time when using the Observer pattern?

What kinds of “static redundancy” can appear as well?

c. In “Visitor Revisited,” why is it necessary to have the NewPresenter class override the visit(Subject *) method?

What is the argument for putting the downcast there, instead of in the accept(Presenter&) method of the RebateSubject class?

d. In “Generation Gap,” what does the CoreClass role in the pattern’s solution structure contain?

What does the ExtensionClass role in that same solution structure contain?

e. In “Type Laundering,” please describe how the framework, which knows nothing of the specific application domain, can create instances of domain-specific subclasses.

Please also describe how application code can access operations that are specific to those subclasses, when only a pointer (or reference) to the base class type is given to the application code.

f. In “Thanks for the Memory Leaks,” which method(s) of the Cursor class provide support for reference counting in the solution that is shown?

Specifically, what support for reference counting do they provide in that solution?

g. In “Pushme-Pullyu,” please explain how the nextEvent () method “centralizes” all types of events.

What is doneto address the problems that this centralization causes?

  1. (10 points): Please answer the following questions about the Multicast Pattern in the fourth chapter of the Pattern Hatching text.

What is meant by saying a system isevent-driven?

Why are event-driven systems typically fairlycomplex?

Please describe how having clients (or handlers) register for eventsin which they are interested helps remove unnecessarycomplexity.

Why is the third design force in the Applicability section (potentially) language-specific?

How does the Typed Message pattern help to complement the Observer pattern (potentially eliminating the need for a Multicast pattern)?

  1. (14 points): Based on the discussion in the 5th chapter of the Pattern Hatching textbook, please explain in your own words why each of the following habits is important to writing (and possibly also to using and/or teaching) design patterns:

a. Taking Time to Reflect

b. Adhering to a Structure

c. Being Concrete Early and Often

d. Keeping Patterns Distinct and Complementary

e. Presenting Effectively

f. Iterating Tirelessly

g. Collecting and Incorporating Feedback

  1. (6 points) Imagine you are designing a collection of different container classesthat willstore pointers to some abstract base class type. Assume thatin each of these containers you need to provide a constructor that would do a deep copy (copying the objects as well as the pointers to them) from each of the other kinds of containers into the container instance that is being created. Please answer the following questions regarding the following design forces that this
  1. the constructor should be able to access all of the objects in the other container sequentially, from beginning to end, without knowing the internal representation of the other container;
  1. When it accesses each object in the other container, the constructor should create a new object instance that has the same actual type (i.e., belongs to the same specific subclass of the abstract base class to which the containers point) and state as the object in the other container.

Of the GoF design patterns we have studied so far this semester, which two of them would best help you address these design forces?

Please draw a collaboration diagram or interaction diagram (whichever you prefer) that shows how the sequence of method calls through which the constructor would interact with the other container and with the objects in it, according to these two patterns:

  1. (8 points): please describe two of the most important requirements for your team project that were introduced in the second project cycle:

Please describe the design forces that resulted from those requirements:

  1. (8 points): Please name the GoF design patterns that were used to resolve the design forces described in the previous question:

Please describe how each of those design patterns resolved those forces in your team’s final project design: