18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

THE MICROSOFT COMPONENT OBJECT MODEL<br />

Workspace-<br />

Factory<br />

Access-<br />

Workspace-<br />

Factory<br />

Workspace<br />

This is a simplified portion of the geodatabase<br />

object model showing type inheritance among<br />

abstract classes, coclasses, and instantiation of<br />

classes.<br />

IBirth<br />

Interfaces<br />

Classes<br />

Human<br />

IBirth<br />

ITalk<br />

IWalk<br />

IDeath<br />

ITalk<br />

IWalk<br />

Dog<br />

IBirth<br />

IWalk<br />

IDeath<br />

IDeath<br />

IFly<br />

Parrot<br />

IBirth<br />

ITalk<br />

IWalk<br />

IFly<br />

IDeath<br />

This diagram shows how common behavior,<br />

expressed as interfaces, can be shared among<br />

multiple objects, animals in this example, to<br />

support polymorphism.<br />

not a shortcoming since individual classes can implement multiple interfaces. See<br />

the diagram to the lower left on polymorphic behavior.<br />

Within ArcObjects are three types of classes that the developer must be aware of:<br />

abstract classes, coclasses, and classes. An abstract class cannot be created; it is<br />

solely a specification for instances of subclasses (through type inheritance).<br />

ArcObjects Dataset and Geometry classes are examples of abstract classes. An<br />

object of type Geometry cannot be created, but an object of type Polyline can.<br />

This Polyline object, in turn, implements the interfaces defined within the Geometry<br />

base class; hence, any interfaces defined within object-based classes are<br />

accessible from the coclass.<br />

A coclass is a publicly creatable class. In other words, it is possible for COM to<br />

create an instance of that class and give the resultant object to the client to use<br />

the services defined by the interfaces of that class. A class cannot be publicly<br />

created, but objects of this class can be created by other objects within<br />

ArcObjects and given to clients to use.<br />

To the lower left is a diagram that illustrates the polymorphic behavior exhibited<br />

in COM classes when implementing interfaces. Notice that both the Human and<br />

Parrot classes implement the ITalk interface. The ITalk interface defines the<br />

methods and properties, such as StartTalking, StopTalking, or Language, but clearly,<br />

the two classes implement these differently.<br />

INSIDE INTERFACES<br />

COM interfaces are how COM objects communicate with each other. When<br />

working with COM objects, the developer never works with the COM object<br />

directly but gains access to the object via one of its interfaces. COM interfaces<br />

are designed to be a grouping of logically related functions. The virtual functions<br />

are called by the client and implemented by the server; in this way, an object’s<br />

interfaces are the contract between the client and object. The client of an object<br />

is holding an interface pointer to that object. This interface pointer is referred to<br />

as an opaque pointer since the client cannot gain any knowledge of the implementation<br />

details within an object nor direct access to an object’s state data. The<br />

client must communicate through the member functions of the interface. This<br />

allows COM to provide a binary standard through which all objects can effectively<br />

communicate.<br />

Interfaces allow developers to model functionality abstractly. Visual C++ developers<br />

see interfaces as collections of pure virtual functions, while Visual Basic<br />

developers see interfaces as collections of properties, functions, and subroutines.<br />

The concept of the interface is fundamental in COM. The COM Specification<br />

(Microsoft, 1995) emphasizes these four points when discussing COM interfaces:<br />

• An interface is not a class. An interface cannot be instantiated by itself since it<br />

carries no implementation.<br />

• An interface is not an object. An interface is a related group of functions and<br />

is the binary standard through which clients and objects communicate.<br />

Chapter 4 • <strong>Developer</strong> environments • 61

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

Saved successfully!

Ooh no, something went wrong!