Composition

OO methods support a version of the most basic and essential form of reuse, the combination of possibly many individual components to serve some aggregate purpose. Object composition is different in both concept and execution than procedure, function, or module composition. However it may be used to identical or similar effect. In compositional OO design, a developer defines a class whose instances serve as ``hosts''. Hosts maintain the identities of other ``helper'' objects and send them messages in the course of achieving required functionality.

Many variants exist. For example, one common form of composition is often termed ``delegation''. Here, any of some subset of messages are simply forwarded (delegated) to the object referred to by a certain connection link, but the exact object on the other side of the link may change (be rebound) over time.

Compositional designs may also be categorized with respect to their encapsulation and modularity properties. Pure closed composition is a form of black box reuse. It is among the safest and most conservative possible design strategies, due to:

ADT-style OO designs rely on closed composition. The success of basic libraries containing many such black-box components attests to the utility of closed composition in addressing in-the-small reuse needs.



Subsections