next up previous
Next: About this document ...


Pattern:
Abstract Slicing with DJ
Intent:
Write algorithms at a high level of abstraction.

Motivation:
The AP motivation: Avoid polluting algorithms with accidental details yet write them so that they can handle all that accidental detail without modification.

Applicability:
Applications that involve multiple connected objects that need to be visited.

Structure:
Parameterize methods with abstract object graph slices that are needed to express the methods abstractly. Instead of object graph slices, you may pass any object that leads to an object graph slice together with information contained in the method. It might be necessary to also pass slices as arguments to visitors that need to do subtraversals.

An object graph slice is a subobject of an object; or: an object graph slice is a subgraph of an object graph.

Related idea:
AspectJ supports the notion of an abstract point cut. Types ObjectGraphSlice and TraversalGraph are a kind of abstract point cut.

Implementation:
DJ provides a good implementation of abstract object slices but does not support static checking. That will be added as a separate tool.

The following incarnations of abstract slicing are possible:

Pass class graph as argument
This is the traditional way of writing adaptive programs. The traversal strategies are a part of the algorithm. This approach works well for many kinds of algorithms where the traversal strategies express important algorithmic intent.
void check(ClassGraph cg){
  ...
  cg.traverse(this, strategy, visitor);
}
is an example of a method in this category. An object graph slice will be created implicitly from the class graph, the strategy and this.
Pass class graph and strategy as argument
Suitable when strategy is not known at design time. Example:
void check(ClassGraph tg, Strategy strategy){
  ...
  cg.traverse(this, strategy, visitor);
}
An object graph slice will be created implicitly from the class graph, the strategy and this.

Pass traversal graph as argument
When the same combination of a class graph and a strategy is used multiple times it is useful to pass a traversal graph. Example:
void check(TraversalGraph tg){
  ...
  tg.traverse(this, visitor);
}
An object graph slice will be created implicitely from the traversal graph and this.

Tradeoff:
use of the pattern makes algorithms more generic but each use of the algorithm requires object graph slice preparation. The input object needs to be prepared (adapted) for processing based on the details of the class graph.


 
next up previous
Next: About this document ...
Karl Lieberherr
12/22/2000