Component Object Model (COM)

Component Object Model (COM) technology allows you to build applications from binary components that communicate together.

When you design an application to take advantage of COM, you pull out chunks of your code that stand alone in their functionality (for example, a specific set of functions that calculate a mortgage could go into a COM component). These code chunks are implemented within executable (.exe) files or Dynamic Link Library (.dll) files. COM objects implemented in .dll files are called in-process servers, which can expose functions to outside applications. This means that other applications, even applications written by other companies, can call these exposed functions.

COM and ActiveX: When COM works across networks, it is called Distributed COM (DCOM). COM provides the aggregation (the way in which one object can make use of another object) for ActiveX. COM also provides the mechanism for packaging the parameters to functions (known as marshaling), so that those parameters can be passed across processes (and machines).

A One Sentence Description Of COM: COM is a complicated topic, but we can write a simple one-sentence description that outlines its most important features:

"COM is a specification and a set of services that allow you to create modular, object-oriented, customizable and upgradeable, distributed applications using a number of programming languages."

Let's look more closely at that overlong sentence and its implications to get a fuller picture of the kinds of facilities offered by COM.

  • COM is a specification
    The COM specification describes the standards that you need to follow in order to create interoperable COM components. This standard describes what COM components should look like and how they should behave.
  • COM is a set of services
    The specification is backed up by a set of services or APIs. These services are provided by the COM library, which is part of the operating system on Win32 platforms, and available as a separate package for other operating systems.
  • COM allows modular programming
    COM components can be packaged as DLLs or EXEs — COM provides the communication mechanism to allow components in different modules to talk to each other.
  • COM is object-oriented
    COM components are true objects in the usual sense: they have identity, state and behavior. In certain circumstances, COM components can be treated polymorphically.
  • COM enables easy customization and upgrades to your applications
    COM components link with each other dynamically, and COM defines standard ways of locating components and identifying their functionality, so individual components are swappable without having to recompile the entire application.
  • COM enables distributed applications
    COM provides a communication mechanism that enables components to interact across a network. More importantly, COM provides location transparency to applications (if desired) that enables them to be written without regard to the location of their components. The components can be moved without requiring any changes to the application.
  • COM components can be written in many programming languages
    COM is a binary standard. Any language that can cope with the binary standard can create or use COM components. The number of languages and tools that support COM is sizable, with C, C++, Java, JScript, Visual Basic, VBScript, Delphi, PowerBuilder, and MicroFocus Cobol forming just part of the list.

COM is not about any particular type of application. It's not about controls (that's ActiveX); it's not about compound documents (that's OLE); it's not about data access (that's OLE DB and ADO); and it's not about games and graphics (that's DirectX). But COM is the object model that underlies all these technologies. An understanding of COM is vital to programming any of these technologies successfully.

The Component Object Model

The component object model is built around the notions of components(often called coclasses), objects, and interfaces. These three different entities are defined and related as follows:

  • Loosely, as we have just been discussing, a coclass (named from component object class) is a piece of binary code that implements some kind of functionality. Coclasses can be distributed in DLLs, or in executable files. It is possible for a single module (DLL or executable) to contain more than one coclass.
  • A COM object is an instance of a coclass that gets loaded into memory. (By the same token, one might say that a coclass is a 'blueprint' for a COM object.) It is not unreasonable (indeed, it is quite common) for more than one object of a given coclass to be active at a time.
  • COM interfaces are the means — the only means — by which other components and other programs get access to the functionality of a COM component. An interface is a set of definitions of logically-related methods that will control one aspect of the component's operation. Each component can have one or more interfaces.
 
Copyright © 2002 by EzSofTech. All Rights Reserved.