|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||
See:
Description
| Interface Summary | |
|---|---|
| Composition<E> | This Interface indicates that a class implements the composition design pattern. |
| CompositionView<T> | A Composition View defines for each class the children to be regarded. |
| Class Summary | |
|---|---|
| CompositionView.DefaultCompositionView | Default implementation of a CompositionView. |
| DepthFirstCollection<E> | A collection based on the DepthFirstIterator. |
| DepthFirstIterator<E> | Provides an Iterator that runs depth first through a tree. |
| LeafFilter<E> | Filters all leafs of a tree defined by a
CompositionView. |
This package contains utility classes to work with tree like structures.
As an example here are two classes, one representing a web page consisting of several forms:
public class Page{
Collection forms;
...
}
and one class representing a form consisting of several input fields.
public class Form{
Collection fields;
...
}
To retrieve all fields in a page a programmer would usually write code like this:
Page page;
Iterator pit = page.forms.iterator();
while(pit.hasNext()){
Form form = (Form) pit.next();
Iterator fit = form.fields.iterator();
while (fit.hasNext()){
Field field = (Field) fit.next();
... do something
}
}
With this package you could achieve the same result by describing the structure of
the page:
public class PageView implements CompositionView{
public Collection getChildren(Object o){
if (o instanceof Page) return ((Page) o).forms;
else if (o instanceof Form) return ((Form) o).fields;
}
}
and then use the leaf iterator
Page page;
Iterator fit = new LeafIterator(page, new PageView());
while (fit.hasNext());
Field field = (Field) fit.next();
}
The advantage of this way of programming is the explicit representation of
structural information over implicit representation,
|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||