OOPortal OOPortal

COM Aggregation   «Prev  Next»
Lesson 11

Reusability and Aggregation Conclusion

We covered the following topics in the last two modules:
  1. The difference between reusing a C++ class at the source level and a component at the binary level.
  2. Reusing COM objects via containment/delegation. This technique involves having the outer COM object act as a client to the inner COM object. The outer COM object mirrors interfaces implemented in the inner COM object and forwards calls into the inner COM object. The inner COM object is not aware that it is being reused. The client is not aware of the inner COM object.
  3. Reusing COM objects via aggregation. This technique requires some additional coding in inner COM objects, but does not require the outer COM object to mirror interfaces implemented in the inner COM object. The inner COM object is fully aware that it is being reused and its interfaces are exposed directly to the client. The client is not aware of aggregated COM objects. The client thinks the outer COM object implements all accessible interfaces.

Key terms and concepts

The following key terms and concepts were introduced in this module:
  1. Interface navigation: Using a pointer to one COM interface to get a pointer to another COM interface in the same COM object. IUnknown::QueryInterface supports interface navigation.
  2. Reference counting:Reference counting supports lifetime management of an object. When an object gives an inteface pointer to a client, a reference count is incremented by calling AddRef. The client calls Release when it no longer need the interface pointer. Release decrements the pointer's reference count. When all the reference counts in an object are zero, the object is not being accessed and can be removed from memory.
  3. Object-level IUnknown:Object-level IUnknown is a separate implementation of IUnknown used to identify a COM object. A standard implementation convention is to have all IUnknown methods from other interfaces in an object do nothing other than call through (delegate) to the object-level IUnknown. This centralizes interface navigation and reference counting in one place within a COM object.
  4. Explicit aggregation:In explicit aggregation the outer COM object is coded to know the interfaces supported by an aggregated COM object.
  5. Blind aggregation:Blind aggregation occurs when an outer COM object is asked for an interface it does not know. The outer COM object calls the QueryInterface implementations of all inner COM objects to see if they support the interface.