Context: |
A hierarchical object structure of variable depth. |
||||||
Challenge: |
To express the hierarchy using object-structure. |
||||||
Skill: |
(Does not involve significant functionality.) |
||||||
Participants: |
|
||||||
Signature: |
Subtrees contain (or reference) Nodes, where each may be either a Leaf or itself a Subtree (thus, giving a tree structure). |
||||||
Comments: |
The Node is a flat interface. In case of an abstract base class it should be devoid of implementation. A binary version (where subtree is a concrete class) is possible but error-prone. A unary version (i.e. simple reflexive association) is possible where all Nodes feature the same behavior, with their tree position reflecting a changeable status, rather than permanent role). |
||||||
Used by: |
Decorator (1:1), Composite (1:n). |
||||||
Scope: |
General. |