文档介绍:接口编程基础(I)
Lesson overview
COM: ponent Object Model
类Working classes
接口Interfaces
多态Polymorphism
接口查询QueryInterface
测试一个对象的引用Testing an object reference
Is it nothing?
What type of object is it?
2
COM is a standard for creating classes
Classes can be reused between applications
Independent of programming language
All ArcObjects classes
Technologies based
Object Linking and Embedding (OLE)
OLE DB
ActiveX is any technology built
DCOM +
3
COM classes have interfaces
对象拥有一个或多个接口
接口是定义了一组方法和属性的逻辑关系
与对象的通信是通过接口来进行的
RaceCar
Accelerate
Brake
Fuel
停靠站
圈速度
IRace
IDrive
垃圾车
加速
刹车
燃料
拾起
倾倒
IGarbage
IDrive
4
classes with an interface
Dim <variable> As <some interface>
Interfaces group properties and methods
Dim pGarbage As IDrive
Set pGarbage = New GarbageTruck
= "Full"
Working with classes
GarbageTruck
Accelerate
Brake
Fuel
PickUp
Dump
IGarbage
IDrive
5
More on interfaces …
一个组合音响的例子
一个对象可以播放收音机、磁带、CD
必须使用适当的接口
如果选择了播放磁带的接口,则不能收听收音机
IRadio
ITape
ICD
Dim pBBox As ITape
Set pBBox = New BoomBox
= True
6
IDrive
燃料
加速
刹车
多态
许多不同的类可以支持相同的接口
拥有相同的所有的方法和属性
可以有不同的执行方式和拥有不同的属性值
7
ArcObjects 多态
许多ArcGIS的类都表现出多态的特性
General interfaces for all subtypes
ILayer: All layer types (raster, tin, feature, etc.)
IGxFile: All atalog file types (shapefile, map, table, etc.)
IActiveView: Map (data view) and PageLayout (layout view)
Several others …
8
Using methods and properties
Dim the variable pointing to an interface
Instantiate the object (Set)
Call methods, set properties
Only use methods and properties for the declared interface
'Create a new RaceCar with IDrive
Dim pCar As IDrive
Set pCar = New RaceCar
= "Full"
RaceCar
Accelerate
Brake
Fuel
PitStop
LapTime
IRace
IDrive
9
Getting other interfaces
QueryInterface (QI)
Access other methods and properties
Q I
RaceCar
Accelerate
Brake
Fuel
PitStop
LapTime
IRace
IDrive
'Create a new