Recursive Composition
Objects can be composited recursively with the use of recursive types or references. Consider a tree. Each node in a tree may be a branch or leaf; in other words, each node is a tree at the same time when it belongs to another tree.
One implementation for the recursive composition is to let each object have references to others of the same type. In C, for example, a binary tree can be defined like:
struct bintree { struct bintree *left, *right; // some data };If pointers left and right are valid, the node is thought to be a branch referring to each tree to which left and right point. If not, the node is a leaf. In this way, the recursion can be terminated.
Another is to use a tagged union. See tagged union for an example.
Read more about this topic: Object Composition
Famous quotes containing the word composition:
“When I think of God, when I think of him as existent, and when I believe him to be existent, my idea of him neither increases nor diminishes. But as it is certain there is a great difference betwixt the simple conception of the existence of an object, and the belief of it, and as this difference lies not in the parts or composition of the idea which we conceive; it follows, that it must lie in the manner in which we conceive it.”
—David Hume (17111776)