Object Oriented Design Course : Exercise 2
Exercise 2 - Various Subjects
Deadline April 23rd, 2003 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++.

Multiple Dispatch

Read this paper first, and answer the following questions:
  1. Assume that multiple dispatch is not available, and you must code intersect() for four Shape descendant classes - Circle, Square, Rectangle, Ellipse. Each shape can be intersected with any other, in any order: if, for example, c is a circle and s is a square, then both c.intersect(s) and s.intersect(c) must be supported. Compare the amount of code and the number of compilation dependencies between implementing these methods with and without using multiple dispatch.
  2. For each of the two implementations of multiple dispatch the paper offers, explain why it wouldn't work if C++ had no support for virtual inheritance, and normal inheritance would have been used instead).

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. Assuming that no commercial debugging tool is available to you, offer practical ways to:
    • Test whether your program is suffering from memory leaks.
    • Finding where the leak is: which objects should have been collected but are not, and who is holding the extra reference that prevents their collection.
Submission Submit a zip file contains the document with your answers.
Resources