Object Oriented Design Course : Exercise 2
Exercise 2 - Various Subjects
Deadline March 31st, 2005 at Ross closing time
Description

The Acyclic Visitor Design Pattern

Read this paper first , and answer the following questions:
  1. Compare the Visitor and Acyclic Visitor design patterns in the following areas:
    • Performance
    • Number of classes
    • Compilation dependencies
    • Amount of "glue" code the pattern requires
  2. Under which conditions is each of the patterns preferable to the other? Give at least one case in which each pattern is better than the other.
  3. Define the terms upcast, downcast and crosscast. For each one of them, give an example of a useful use of it in C++.

Code Generators

Read this paper first, and answer the following questions:

  1. What are code generators good for? List scenarios in which using a code generator would save time, reduce effort or prevent errors.
  2. One of the possible uses of code generators is to generate code from UML diagrams. For example, assume that a given UML tool stores class diagrams in XML files, and you would like to be able to generate C++ and Java interfaces and classes from them using Velocity. Explain which files play each of the roles in code generation - data model, template, template engine and target - and which files you'll have to write to be able to generate code for classes using Velocity.

Exception-Safe Generic Containers

Read this paper first , and answer the following questions:
  1. Quote: "More generally, mutator functions should not return T objects by value". Explain why this is a problem. State a general rule of generic class design, that designers must follow to avoid this problem.
  2. Explain why the three methods of StackImpl are both exception-neutral and exception-safe.
  3. Write a full implementation of class Stack<T> in the case where StackImpl<T> is used by containment: that is, Stack<T> has a private data member StackImpl impl_. Remember that you can only require a copy constructor and a non-throwing destructor from T.

Memory Management

Read this paper first, and answer the following question:
  1. Give concrete code examples of how a memory leak can be created in Java in these cases:
    • A flyweight factory that does not release unused flyweights.
    • Observer objects that are not un-registered when they are no longer used.
    • A hash table that maps thread objects to per-thread data objects, and does not delete entries when threads terminate.

    Show the code required to fix the bug in each case.

Submission Submit a zip file contains the document with your answers.
Resources