To support aggregation, a COM object must provide an implementation that supports the following guidelines.
A COM object implements an object-level IUnknown interface. This means the inner object implements an IUnknown interface that is separate and distinct from other COM interfaces in the object. In COM literature, this is called the nondelegating IUnknown. The nondelegating IUnknown performs normal IUnknown functionality
This guideline requires each COM object that supports aggregation to provide a separate, object-level, IUnknown implementation, that is, the nondelegating IUnknown. The outer COM object will use the nondelegating IUnknown to retrieve interfaces from the inner object and to release the inner object. The nondelegating IUnknown is not visible to the client.
The IUnknown methods in all interfaces exposed by the inner COM object to the client as part of the aggregation (that is, all QueryInterface, AddRef, and Release methods except those in the object-level IUnknown) must not perform any interface navigation or reference counting.
Instead, they must delegate all calls into the outer object's IUnknown. In COM literature, this type of IUnknown is called a delegating IUnknown because it delegates all functionality to the outer object's IUnknown.
This guideline supports interface navigation and reference counting across multiple objects in the aggregation by centralizing all IUnknown functionality in the outer COM object. This allows the outer COM object's IUnknown to control interface navigation and reference counting on all interfaces, in all aggregated objects.
We will discuss how the inner object gets the outer object's IUnknown pointer in a subsequent lesson.
nondelegating and delegating IUnknown interfaces with multiple inheritance requires you to specify a stand-alone IUnknown interface.
Additionally, this interface must use different names (but the same function attributes and parameter types) for QueryInterface, AddRef, and Release to avoid name conflicts with the IUnknown members of other interfaces.
The following diagram shows a COM object with nondelegating and delegating IUnknown interfaces.
Aggregation - Exercise
Click the Exercise link below to apply what you have learned about aggregation guidelines.
Aggregation - Exercise