Containment/delegation allows some flexibility. For example, when the outer object exposes the same interface as the inner object, it can filter calls to the inner object by manipulating the method's parameters or augmenting the inner object's results.
The outer object can also choose not to delegate a call to the inner object.
For example, depending on a dynamic data set, OuterCOMObj's implementation of IX1::x1 may not call InnerCOMObj's implementation of IX1::x1.
Another variation of containment/delegation is that the outer object does not expose the same interface as the inner object. Instead, it delegates to methods in the inner COM object from a different interface.
For example, instead of implementing IX1, OuterCOMObj implements ZZ1 with methods z1 and z2.
In ZZ1::z1, OuterCOMObj delegates by calling InnerCOMObjIX1::x2.
COM containment is similar to C++ containment.
The outer component is simply a client of the inner components. The outer component implements its own interfaces using the inner components.
The clients of the outer component do not know that the outer component uses other components to carry out its services.
The outer component can also re-implement an interface supported by an inner component by forwarding calls to the inner component. The outer component might specialize the interface by adding scode before and after the code for the inner component.
COM gives two systems to code reuse called
In the first and more normal component, one item (the "external" object) basically turns into the client of another, inside utilizing the subsequent item (the "inward" object) as a supplier of administrations that the external article tracks down helpful in its own execution. For instance, the external item might carry out just stub works that only pass through calls to the inward article,
just changing item reference boundaries from the inward item to itself to keep up with full embodiment.
This is actually the same than an application calling capabilities in a working framework to accomplish similar closures, different items just expand the usefulness of the framework. Seen remotely, clients of the external item just at any point see the external article the inward contained object is totally covered up "embodied" from view.
Furthermore, since the external item is itself a client of the inward item, it generally utilizes that internal item through an obviously characterized agreements: the internal article's connection points.
By carrying out those points of interaction, the internal article signs the agreement promising that it won't change its way of behaving out of the blue.