The handle/body idiom -- invocation context
The handle/body idiom
allows for
separating the definition of a component's
interface (the handle class) from its
realization (the body class). All intelligence is
located in the body, and (most) requests to the handle object
are delegated to its implementation.
In order to optimize the creation and destruction of dynamically
allocated objects, one may use techniques such as
representation or resource sharing
and reference counting.
However, the use of these techniques can put a heavy burden on
the application programmer.
The handle/body idiom was
introduced in [Coplien] as a means to hide the use
of such low-level issues
from the application programmer,
by adding a level of indirection,
that is delegation to a 'body' implementation
object.
An additional advantage of applying the idiom is that
it allows interface classes to become stable
while improving on the realization.
In practice, by applying the idiom one may avoid
recompilation of dependent code as long as the interface class
does not change.