CHAP04_对象模型图

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Classes
can inherit from other classes

Subclass inherits everything from superclass
IFeatureLayer featLayer = new FeatureLayerClass();
//Assign general attributes on ILayer interface featLayer.Name = layerName; featLayer.ShowTips = true;
Introduction to Programming ArcGIS Using C#
4-5
Abstract classes

Specification for subclasses
Cannot be instantiated
ILayer layer = map.get_Layer(index); bool layerVisible = layer.Visible;
When using getters:
Some
methods return a value (e.g., string, int)
string name = map.Name; //Value Console.WriteLine("The map name is: " + name); Others
IFeatureLayer fLyr;
Relationship Association
Symbol 1 0..1
fLyr = new FeatureLayerClass();
//Only one object allowed
fLyr.FeatureClass = fC;
Multiplicity
M..N * or 0..* 1..*
4-7
Attributes and methods

Classes contain attributes and methods
Each
has its own OMD symbol

Attributes
Read/write
Read-only Write-only
Special
writable attribute
return an object reference (e.g., ILayer)
ILayer layer = map.get_Layer(mapIndex,layerIndex); //Object Console.WriteLine("The layer name is: " + layer.Name);
Interfaces

Objects communicate through interfaces
OMD symbol
All
names prefaced(以…开始) with "I"
IMap IActiveView IBasicMap
IBasicMap2

Examples:
IMap IActiveView
对象模型图
Copyright © 2014 HHU All rights reserved.
Introduction to Programming ArcGIS Using C#
Learning objectives

Discuss fundamental OMD components
Interfaces,
4-3
OMD symbols
Copyright © 2014 HHU All rights reserved.
Introduction to Programming ArcGIS Using C#
4-4
CoClasses

Instantiate using the keyword new
IMap map = new MapClass();
4-10
Method signatures – single output

Some methods expect parameters to be placeholders (占位符)for return values
Return a single result value
string errorMessage; //Validation examples: subtype, attribute rules, etc. bool validated = row.validate(out errorMessage); //Test if attribute is valid if(validated != true){ Console.WriteLine("Row not validated because " + errorMessage[0]); }
Copyright © 2014 HHU All rights reserved.
Introduction to Programming ArcGIS Using C#
4-2
Object model diagrams

Help you write code
Show:
Interfaces
Core Geodatabase Model
attributes, methods, classes, and abstract classes

Identify OMD symbols

Describe relationships between classes
"Is
a," association, composition, and "creates a"
//Event object represents a mouse-based event (e.g., onMouseDown)
tocControl.HitTest(e.x, e.y,
map,
layer, group, groupIndex);
Copyright © 2014 HHU All rights reserved.
Association

Connection between two classes
Have multiplicity(多样性)
Can
be defined at both ends of relationship
Constrains
number of objects that can be associated
by value
//Set Name attribute by value layer.Name = layerName;
holds a value or a copy (static)
Set

by reference
holds a reference
Attribute
//Set SpatialReference attribute by reference
ILayer
Relationship "Is a" type of
Symbol
Layer
IFeatureLayer
FeatureLayer
IRasterLayer
RasterLayer
4-14
Copyright © 2014 HHU All rights reserved.
Introduction to Programming ArcGIS Using C#

Copyright © 2014 HHU All rights reserved.
Introduction to Programming ArcGIS Using C#
4-11
Method signatures – multiple outputs

Return multiple result values
Introduction to Programming ArcGIS Using C#
4-12
Relationships

Ways classes can be related
Relationship "Is a" type of Is composed of "Creates a" Association Row Map Table Symbol
*
Layer
FeatureClass
0..1
FeatureLayer
Copyright © 2014 HHU All rights reserved.
Introduction to Programming ArcGIS Using C#
4-13
"Is a" inheritance

Normally occurs when abstract class present

Instantiable: obtain reference from existing objects
IMap map = (IMap) mapDoc.ActiveView.FocusMap;

OMD symbol
IMap wenku.baidu.comActiveView
Map
Copyright © 2014 HHU All rights reserved.
Layer
layer.SpatialReference = someSpatRef;
If
referenced object changes, attribute is affected (dynamic动态的)
Copyright © 2014 HHU All rights reserved.
Introduction to Programming ArcGIS Using C#
esriTOCControlItem item = esriTOCControlItem.esriTOCCOntrolItemNone;
//TOC item clicked (e.g., Layer)
IMap map = null; //Map object, if selected ILayer layer = null; //Layer object, if selected Object group = null; //Group layer, if selected Object groupIndex = null; //Layer index, if group layer selected

OMD symbol
Class
ILayer
name is italicized(下划线)
Layer
?
IFeatureLayer
FeatureLayer
IRasterLayer
RasterLayer
A
Copyright © 2014 HHU All rights reserved. Introduction to Programming ArcGIS Using C# 4-6
Methods
Attributes Classes
Relationships

One conceptual diagram
Many
packages
Copyright © 2014 HHU All rights reserved.
Introduction to Programming ArcGIS Using C#
A
Copyright © 2014 HHU All rights reserved. Introduction to Programming ArcGIS Using C# 4-9
Set attributes

Each attribute has associated setters
Set
Attribute

Methods
Normally
requires arguments
Copyright © 2014 HHU All rights reserved.
Introduction to Programming ArcGIS Using C#
4-8
Get attributes

Each attribute has associated(关联的) getters
Map
IBasicMap2
Etc.

Suffix(后缀、下标) index number signifies new functionality
Copyright © 2014 HHU All rights reserved.
Introduction to Programming ArcGIS Using C#
相关文档
最新文档