Lesson 1
Reusability, Containment, and Delegation
Containment Delegation
Module introduction
In
COM Fundamentals I, we studied basic COM (Component Object Model) concepts and development techniques. We will put these techniques to use to expand our repertoire to include COM
reusability. Before we do that, let us step back and discuss how COM fits into a newer development technique called
component software. Component software promotes interoperability, application integration, and reusability at the binary level. This module presents a brief overview of component software and how COM is used as a component software development technology. At the end of this module, you will:
- Understand how component-based software reusability mechanisms differ from other software development reusability mechanisms
- Understand COM's containment/delegation reusability mechanism
Inside Microsoft Programming
Containment and Aggregation versus Inheritance
In normal C++ programming, you frequently use inheritance to factor out common behavior into a reusable base class.
COM uses containment and aggregation instead of inheritance. Let's start with containment. Suppose you extended the spaceship simulation to include planets in addition to spaceships. Using C++ by itself, you would probably write a COrbiter base class that encapsulated the laws of planetary motion. With COM, you would have "outer" CSpaceship and CPlanet classes plus an "inner" COrbiter class. The outer classes would implement the IVisual interface directly, but those outer classes would delegate their IMotion interfaces to the inner class. The result would look something like this. This document contains the specification to the Component Object Model (COM), an architecture and supporting infrastructure for building, using, and evolving component software in a robust manner. This specification contains the standard APIs supported by the COM Library, the standard suites of interfaces supported or used by software written in a COM environment, along with the network protocols used by
COM in support of distributed computing.