COM Programming  «Prev  Next»
Lesson 3 What you need
Objective Discover what you need to take this course.

Com Fundamentals (Course Requirements)

Containment, Delegation and Aggregation

The Component Object Model (COM) is a binary-interface standard for software components introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in any language that supports the technology. COM is a set of interfaces that allows different components to communicate. These components can be from the same process, different processes, or even different machines. The relationship between Containment, Delegation, and Aggregation is fundamental to the operation of COM and helps in managing and reusing code.


Containment is the first method for implementing one object in terms of another. It's a fundamental object-oriented programming concept where a given object contains another object. This is also sometimes known as composition. In this model, the containing (or outer) object provides services of the contained (or inner) object but does not expose the inner object’s interfaces to the outside world. In the context of COM, the outer object has its own v-table and it implements the interfaces of the inner object by providing a new set of functions. The contained object is hidden and the client cannot directly invoke the methods of the contained object. In essence, it's a relationship of "has-a". For instance, if you have an object Car, it could contain another object Engine, but the user of Car does not directly interact with Engine.


Delegation refers to a design pattern where an object, instead of performing one of its stated tasks, delegates that task to an associated helper object, or delegate. This is a technique where the responsibility of a particular code routine is transferred from one object to another. In a COM context, if the containing object doesn't want to implement some functions of the inner object's interface, it can directly forward the client's call to the inner object's function, this process is known as delegation. Delegation allows an object to pass off (or delegate) part of its responsibilities to another object.


Aggregation is an advancement over Containment and Delegation in COM. It's a type of object composition where one object (the aggregator, or outer object) 'exposes' the interface of another object (the aggregatee, or inner object) thereby allowing the inner object's methods to be directly invoked by clients. In COM, with aggregation, the outer object exposes the interfaces of its inner objects, effectively merging or "aggregating" their functionalities. This mechanism is a compromise between providing a lot of power and maintaining some control over the inner object's code. In terms of object-oriented design, aggregation is a "has-a" relationship, but the client can see the inner object as part of the outer object.

To summarize, Containment, Delegation, and Aggregation in COM are all about managing object interactions and reusing existing components. Containment is about one object using another privately. Delegation is about passing tasks onto another suited object. Aggregation is about making the functions of one object directly accessible as if they were part of another object. All these techniques help with code reuse, modular design, and the overall maintainability of systems.


To complete COM Fundamentals II successfully, you should acrquire Microsoft C++ from the following website The examples in the course have been done using version Visual C++ 6.0.
No additional software beyond what you need to access this course is required.

Platform support

You can take this course on Windows, Macintosh, or Unix platforms.
As of 2019, Visual Studio 2019 can be run on Mac OS. visual-studio-2019-for-mac-is-now-available. Out of historical reasons, Visual Studio runs best on MS Windows. However, you can choose whichever combination of 1) Operating System and 2) IDE that works best for you.

Course Download

Downloadable course project files are available for this course. They include the binary files you need to complete the course project, as well as completed course project files for both Visual C++ 5 and Visual C++ 6.

Recommended Reading

The following textbook is recommended for this couse as accompanying text.
Inside Microsoft Programming
This books are not required to take this course, but do contain helpful, additional information. You can reach the Bookstore page at any time by clicking the Resources button on the toolbar.

COM Reuse

A further way of reuse that is utilized by COM is aggregation. Aggregation is reuse of a COM component. An aggregation component consists of one outer component and one or more inner components. At run time, the instance of the outer component, called outer object, is the one that deals with the clients. In turn, the outer object will make a request to the system to generate an instance of the inner component, called an inner object.
The outer object, as coded in the outer component, may give its client a pointer to an interface implemented in the inner object. This is the heart of COM aggregation, an instance of a component (the outer component) reuses an implementation made in another component (the inner component) or is contained in an instance of the inner component. The outer component may make only a part of the inner component’s interfaces available to its client.
Hauck tried to use COM aggregation to implement an architecture called Mediator-Based Architecture. This architecture requires a client to be able to access any of the inner component’s interfaces. This is clearly against the specification of aggregation.