Aggregation is almost as simple to implement, the primary difference being the implementation of the three
- AddRef, and
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
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.
This module discussed the following topics.
- The difference between reusing a C++ class at the source level and a component at the binary level.
- 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.
The following key terms and concepts were introduced in this module:
- 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.
- 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.
- C++ reusability
- 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.
- Immutable:COM interfaces are immutable. Once a COM interface is published or distributed its IID and methods can not change.
- Inner COM object
- Outer COM object
- Object composition:The combination of two or more software components into a combined unit that acts like one component.
- Reusability:C++ supports reuse of implementation through inheritance and templates. C++ also supports specification through inheritance of abstract base classes.
- Software component:An independent module that provides services through interfaces. Software components integrate at the binary level.
- 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?