Containment Delegation  «Prev  Next»
Lesson 10

Reusability, Containment and Delegation using COM Conclusion

Aggregation is almost as simple to implement, the primary difference being the implementation of the three IUnknown functions:
  1. QueryInterface,
  2. AddRef, and
  3. Release.
The catch is that from the client's perspective, any IUnknown function on the outer object must affect the outer object. That is, AddRef and Release affect the outer object and QueryInterface exposes all the interfaces available on the outer object. However, if the outer object simply exposes an inner object's interface as its own, that inner object's IUnknown members called through that interface will behave differently than those IUnknown members on the outer object's interfaces, a sheer violation of the rules and properties governing IUnknown. The solution is for the outer object to somehow pass the inner object some IUnknown pointer to which the inner object can re-route (that is, delegate) IUnknown calls in its own interfaces, and yet there must be a method through which the outer object can access the inner object’s IUnknown functions that only affect the inner object.
Aggregation of an inner object where the outer object exposes one or more of the inner object’s interfaces as it's own.
Figure 2-10: Aggregation of an inner object where the outer object exposes one or more of the inner object's interfaces as it's own.

Module Summary

This module discussed the following topics.
  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.
We will study COM's other reuse mechanism, aggregation in the next module.

Key terms and concepts

The following key terms and concepts were introduced in this module:
  1. Aggregation:Aggregation provides a mechanism that allows you to compose several COM objects into one larger composite COM object. Aggregated objects combine with the outer COM object (the aggregator) into what appears to be one COM object that supports the interfaces implemented in all the objects.
  2. Binary-level integration:Software components do not support inheritance. Instead, one component has code in it that accesses and uses the services of another component.
  3. C++ reusability
  4. Call delegation:In containment/delegation when an outer COM object receives a call in an interface it mirrors from the inner COM object - the outer COM object calls into the inner COM object's methods.
  5. Containment/delegation
  6. Immutable:COM interfaces are immutable. Once a COM interface is published or distributed its IID and methods can not change.
  7. Inner COM object
  8. Outer COM object
  9. Object composition:The combination of two or more software components into a combined unit that acts like one component.
  10. Reusability:C++ supports reuse of implementation through inheritance and templates. C++ also supports specification through inheritance of abstract base classes.
  11. Software component:An independent module that provides services through interfaces. Software components integrate at the binary level.
  12. Source-code based dependencies:One or more source files that are needed to integrate an object into a program. Generally, this means that you must compile the definition of a module into your code. For example - to use a C++ class, an include file with the class definition is needed.
Do you have any questions or comments about reusability, containment/delegation, or any of the other material covered so far in this course?