18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

THE MICROSOFT COMPONENT OBJECT MODEL<br />

IClassFactory<br />

InterfaceB<br />

IClassFactory<br />

InterfaceA<br />

IUnknown<br />

IUnknown<br />

Class<br />

factory A<br />

COM<br />

object B<br />

InterfaceB<br />

IUnknown<br />

Class<br />

factory B<br />

IUnknown<br />

COM<br />

object A<br />

IUnknown<br />

COM<br />

object B<br />

A server is a binary file that contains all the<br />

code required by one or more COM classes. This<br />

includes both the code that works with COM to<br />

instantiate objects into memory and the code to<br />

perform the methods supported by the objects<br />

contained within the server.<br />

GUIDGEN.EXE is a utility that ships with<br />

Microsoft’s Visual Studio and provides an easy-touse<br />

user interface for generating GUIDs. It can<br />

be found in the directory \Common\Tools.<br />

The acronym GUID is commonly pronounced<br />

“gwid”.<br />

CLASS FACTORY<br />

Within each server there is an object called a class factory that the COM runtime<br />

interacts with to instantiate objects of a particular class. For every corresponding<br />

COM class, there is a class factory. Normally, when a client requests an object<br />

from a server, the appropriate class factory creates a new object and passes out<br />

that object to the client.<br />

SINGLETON OBJECTS<br />

Although this is the normal implementation, it is not the only implementation<br />

possible. The class factory can also create an instance of the object the first time<br />

and, with subsequent calls, pass the same object to clients. This type of implementation<br />

creates what is known as a singleton object since there is only one<br />

instance of the object per process.<br />

GLOBALLY UNIQUE IDENTIFIERS<br />

A distributed system potentially has thousands of interfaces, classes, and servers,<br />

all of which must be referenced when locating and binding clients and objects<br />

together at runtime. Clearly, using human-readable names would lead to the<br />

potential for clashes; hence, COM uses GUIDs, 128-bit numbers that are virtually<br />

guaranteed to be unique in the world. It is possible to generate 10 million GUIDs<br />

per second until the year 5770 A.D., and each one would be unique.<br />

The COM API defines a function that can be used to generate GUIDs; in addition,<br />

all COM-compliant development tools automatically assign GUIDs when<br />

appropriate. GUIDs are the same as Universally Unique Identifiers (UUIDs),<br />

defined by the Open Group’s Distributed Computing Environment (DCE) specification.<br />

Below is a sample GUID in registry format.<br />

{E6BDAA76-4D35-11D0-98BE-00805F7CED21}<br />

COM CLASSES AND INTERFACES<br />

Developing with COM means developing using interfaces, the so-called interfacebased<br />

programming model. All communication between objects is made via their<br />

interfaces. COM interfaces are abstract, meaning there is no implementation<br />

associated with an interface; the code associated with an interface comes from a<br />

class implementation. The interface sets which requests can be made of an object<br />

that chooses to implement the interface.<br />

How an interface is implemented differs among objects. Thus, the objects inherit<br />

the type of interface, not its implementation, which is called type inheritance.<br />

Functionality is modeled abstractly with the interfaces and implemented within a<br />

class implementation. Classes and interfaces are often referred to as the “what”<br />

and “how” of COM. The interface defines what an object can do, and the class<br />

defines how it is done.<br />

COM classes provide the code associated with one or more interfaces, thus encapsulating<br />

the functionality entirely within the class. Two classes can have the same<br />

interface, but they may implement them quite differently. By implementing these<br />

interfaces in this way, COM displays classic object-oriented polymorphic behavior.<br />

COM does not support the concept of multiple inheritance; however, this is<br />

60 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!