COM Aggregation   «Prev  Next»

COM Aggregation Summary

Do not worry if you feel you do not fully understand aggregation. Our main objective has been to expose you to the terminology and concepts of aggregation. Although we did see fragments of how to implement aggregation using multiple inheritance, we did not dive into a full implementation. We will study how to implement aggregation using the Active Template Library (ATL) later on in this course.
To review, let us summarize what aggregation does:

  1. Aggregation supports a composition of objects where the outer object appears to implement the inner object's interfaces. The collection of aggregated objects and the outer object act as one COM object.
  2. Aggregated objects (inner objects) directly expose their interfaces. Unlike containment/delegation, there is no intermediate interface in the outer object that stands between the client and the inner object's interface.
  3. Even though an aggregated/inner object's interfaces are directly exposed to the client, the client is not aware of the aggregated (inner) objects.

Essential COM
To implement aggregation, we apply the following implementation guidelines:
  1. Inner COM objects must implement a nondelegating IUnknown. This acts like a "normal" IUnknown implementation.
  2. All IUnknown functions in interfaces exposed through aggregation, other than the nondelegating IUnknown, must delegate their functionality to the outer object's IUnknown.
  3. At start-up, outer COM objects create an instance of each aggregated object. They tell the newly instantiated inner COM object about the aggregation by passing in their IUnknown pointer into CoCreateInstance (or IClassFactory::
    CreateInstance
    ) and asking for IUnknown. In response, the inner COM object returns its nondelegating IUnknown to the outer object.
  4. Outer COM objects use the aggregated COM object's nondelegating IUnknown to perform interface navigation. The outer COM object can support interfaces in aggregated COM objects via explicit or blind aggregation.
  5. The outer COM object releases all aggregated objects as part of its termination sequence by calling Release in each nondelegating IUnknown it holds.