Exercise 2 - Various Subjects
Deadline April 26th, 2006 at Ross closing time
Description

Design Patterns for Generic Programming

Read this paper first; focus on sections 1, 2 and the descriptions of the Abstract Factory, Decorator and Visitor patterns. Answer the following questions:
  1. For each of these three patterns, compare their "classic" object-oriented versions with the generic versions that the paper presents, in terms of:
    • 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 version is better than the other, for each of the three patterns.

Memory Leaks in Java Code

Read this paper first, and answer the following questions:

  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.
  2. Assume that you need to debug an application with one of the two bugs from the previous question. Which features of a performance analysis/debugging tool are most useful for such a task? Give examples of how they are used, from the stage finding that a memory leak exists at all, to the stage of finding the source code lines that cause the problem, and verifying that the problem was fixed.

Code Generation Models

Read this paper first, and answer the following question:

  1. For each of the first five presented models of code generators, list a scenario (different than the one given in the paper) in which using such a code generator would save time, reduce effort or prevent errors.
  2. Consider code generation from UML Models, for example the generation of Java code from UML class and sequence diagrams. Analyze the potential benefits and drawbacks of this approach with respect to quality, consistency, productivity and abstraction. Under which conditions is this approach most valuable?

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.
Submission Submit a zip file containing the document with your answers, in PDF, TXT or HTML format.
Resources