|Lesson 8|| Aggregation guidelines: outer objects |
|Objective|| List guidelines for aggregating outer objects.|
Aggregation Guidelines and Outer Objects
To aggregate other COM objects, an outer COM object must adhere to the following guidelines:
- The outer COM object must create an instance of each inner/aggregated COM object. Normally, as part of its initialization sequence, the outer object creates instances of the COM objects it aggregates.
- The outer object must release the inner object's nondelegating
IUnknown when it is released. This guideline tells us to release the inner COM object when the outer COM object is released.
Guidelines 1 and 2 tell the outer object to keep the aggregated objects in synch with its own state.
When the outer object is created, it creates and aggregates the inner objects. When the outer object terminates, it releases the inner objects.
The outer object's implementation of
IUnknown::QueryInterface must be able to use the inner object's nondelegating
IUnknown to obtain interface pointers into the inner object to provide them to the client.
This guideline states that the outer object uses the nondelegating
IUnknown interfaces of each aggregated object.
When a client asks the outer COM object for an interface it does not support, the outer object can query each aggregated object for the requested interface by calling
QueryInterface in the nondelegating
Outer objects can handle interface navigation into inner objects in two ways:
- explicitly or via
- blind aggregation.
Fix Bug Outer-Com Object - Exercise