Using COM to develop universal GIS applications
What is COM
A Foundation
COM is a programming architecture that provides a generic way to distribute reusable interfaces
in binary format. It allows different programming languages and environments to communicate
with one another using an Open Software Foundation standard called Remote Procedure Call,
simply referred to as OSF RPC. RPC is a wire protocol that uses low level operating system calls
to allow different process spaces to communicate with one another. These process spaces can be
running on the same computer, or on separate computers connected together with standard
network protocols. COM has a standard API that supplies developers with a common way to
create and destroy COM components. The COM API is contained within a DLL (dynamic link
library) that is loaded in the process space that the COM application is running in.
Problems
One the biggest advancements brought to the Windows developer was the concept of the DLL.
DLLs allowed applications to reuse common functions simply by dynamically loading a file and
making use of the functions that it exposes. As DLLs became widely used, a concept referred to
as ‘DLL hell’ was coined because of the trouble caused by these DLLs. When applications were
upgraded, modified, and extended, it became very troublesome to maintain these DLLs. The
DLL had to be referred to by an exact file system path and physically loaded into the application
process space. The application expected the DLL to contain the same functions and look the same way every time it was loaded. A simple change to a DLL function made by one developer
could easily affect every developer on the team stopping development for days. Something had
to be done.
Reusability?
Internally, Microsoft’s application development division fought through this problem and
developed a specification for reusing DLLs efficiently. Using something called a COCLASS to
expose interfaces instead of functions, applications now have to ask for interfaces instead of
expecting them to be there. This way they can gracefully handle cases when an interface is not
exposed. DLLs are still used to house these COCLASSes, but they can also be distributed in exe
format. Using the windows registry, the DLL location, as well as other attributes about the COM
components, are stored and accessed. Each COCLASS and interface is referred to using
something called a GUID (Globally Unique Identifier) which is guaranteed to be unique across
the world. Using GUIDs to name interfaces and COCLASSes eliminates the threat of naming
collision between components.
Generally, COM is a written contract that states what interfaces and methods a component
exposes, how they are used, and what they return. This contract should never be broken. Method
syntax should never change because it would break any clients currently using the method. The
implementation of the method can change so long as the same results are returned. If a new
syntax is needed, to offer additional parameters for instance, a new method should be added to
the interface instead of changing the signature of the existing one. This guarantee allows clients
to freely use a components interfaces and methods without fear of losing them.
|