AE interface jump

Deeply understand the meaning of ESRI ArcGISEngine programming interface jump

   

1. What is interface jump (QI-Querry Interface)

QI is an important technical detail in the development of ArcGIS Eingine. According to the Querry Interface literal translation, it is the query interface, but its essence refers to the transfer from one interface of the class to another. Therefore, it is also called interface jump.

When learning object-oriented programming, it is known that a class may contain many attributes and methods. These attributes and methods need to be grouped, and each team can define an interface. In this way, each class may contain multiple interfaces. For example, the Polygon class contains many interfaces such as Ipolygon, Igeometry, and Iarea. When developers want to know the perimeter of a polygon, they must use the Length property under the Ipolygon interface. If you want to know the area, you need to use the Area property under the Iarea interface. That is, in the process of using an object, it is often necessary to jump between unused interfaces. This is called interface jump (QI).

2. How to QI

The following is a specific example to illustrate:

IPolygon pPolygon;

pPolygon = new PolygonClass();

double curveLength;

curveLength = pPolygon.Length;

IArea pArea;

pArea = pPolygon as IArea; // QI happened here

double shapeArea;

shapeArea = pArea.Area;

3. The essence of QI

IPolygon and Iarea are obviously two interfaces, why write in QI:

pArea = pPolygon as IArea;

The reason for the above statement is legal, you need to understand the interface variables, through the statement:

IPolygon pPolygon;

It declares an interface variable named pPolygon. The interface variable is essentially a variable used to store a memory address, but it is different from the general address variable, because when using interface variables, it must comply with the interface specifications.

Pass the statement:

pPolygon=new PolygonClass();

The interface variable pPolygon stores the first address of the PolygonClass () object in memory. It can be understood that pPolygon points to a Polygon object. And when using the pPolygon variable, it must comply with the specifications of the IPolygon interface. For example, there is only the Length property without the Area property, and the Length property is read-only (the so-called interface is actually a specification).

Statement:

pArea = pPolygon as IArea ;

It is to assign the first address of a Polygon to pArea, but the use of pArea variables must conform to the specifications of the IArea interface.

Therefore, the so-called QI is to assign the first memory address of an object to different interface variables in order to access different attributes and methods according to different interface specifications.

 

Reprinted from https://www.cnblogs.com/aipingniu/p/6014814.html, invaded and deleted.
Published 8 original articles · won 16 · 40,000+ views

Guess you like

Origin blog.csdn.net/knkn123/article/details/88103794