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:
- 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.
- 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.
- Even though an aggregated/inner object's interfaces are directly exposed to the client, the client is not aware of the aggregated (inner) objects.
To implement aggregation, we apply the following implementation guidelines:
- Inner COM objects must implement a nondelegating
IUnknown. This acts like a "normal"
IUnknown functions in interfaces exposed through aggregation, other than the nondelegating
IUnknown, must delegate their functionality to the outer object's
- 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
IClassFactory::) and asking for
IUnknown. In response, the inner COM object returns its nondelegating
IUnknown to the outer object.
- 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.
- The outer COM object releases all aggregated objects as part of its termination sequence by calling
Release in each nondelegating
IUnknown it holds.