OOPortal OOPortal

Basic COM  «Prev  Next»
Lesson 3COM terminology and objects
ObjectiveDescribe COM terminology and COM objects.

COM Terminology and Objects

COM is an object-based technology in that it specifies the behavior of objects and how to integrate (i.e. use) objects. Unlike C++, COM does not require users of an object to know the internal layout of the object. A COM object can be thought of as a container for one or more COM interfaces. COM objects are implemented within a COM server. To denote a COM object and its interfaces, we use a box with connected interface diagrams:
COM object consisting of 1) IUnknown and 2) Three interfaces

A COM server is a Windows DLL or EXE that houses COM objects.

Class objects and class factories

COM objects are created by another type of object, a Class object. Class objects are implemented within a COM server. The most common type of class object is a class factory. A class factory is a class object that implements an interface called IClassFactory. IClassFactory defines a method that creates an instance of a COM object.

To create a COM object, a client asks COM for the class factory that knows how to create a specific COM object. In response, COM asks the COM server for the requested class factory. The server returns a pointer to the class factory's IClassFactory interface to COM, and COM returns it to the client. Using methods in IClassFactory, the client creates instances of the COM object.
We need one dedicated class factory for each type of COM object supported, for example, if a server implements COM objects A and B, it must implement two class factories: one for A and one for B.

A COM server consisting of 1) Two Class Factories and 2) Two Com Objects

Even though COM has the notion of objects, all interactions between the client and server are through interfaces. This means the only way to talk to a COM object is through its interfaces. This also means that COM objects do not directly expose data members.

Com Basics - Quiz

Click here to check your understanding of COM basics.
COM Basics - Quiz