Description |
The Acyclic Visitor Design PatternRead this paper
first
, and
answer the following questions:
- 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
- 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.
- 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:
- What are code generators good for? List scenarios in
which using a code generator would save time, reduce effort
or prevent errors.
- 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 ContainersRead this paper
first
, and
answer the following questions:
- 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.
- Explain why the three methods of
StackImpl
are both exception-neutral and exception-safe.
- 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 ManagementRead
this paper first, and answer the following question:
- 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. |