AE development-qi (interface query)

Source: Internet
Author: User
Tags imap

Hello everyone, I started to learn about arcengine some time ago and read some basic concepts. However, I am not very clear about the concept of Qi. I read some documents on the Internet today and understand why, I don't dare to share it with you. I hope it will be helpful for beginners like me.

Developers who know AE know that AE is programmed based on interfaces. All classes in AE are implemented through interfaces. I personally think this is an excellent architecture and it is extremely convenient for expansion programs. For example, when I want to customize a map operation class, I can use the interfaces defined in AE to implement the attributes and methods of these interfaces. However, when we don't need an interface, but write it all into a class, which means to change the methods or attributes of the class in the future, we can imagine how much maintenance work will be done in the future. But for the interface, it is different. We can define attributes and methods in the interface, and then let these classes implement these attributes and methods, without the need for major class operations, it saves both time and cost. Haha.

After talking about this, I want to talk about the advantages of using interfaces. But it is often easier to understand things with many benefits. For example, interface query (QI): conversion between different interfaces in the same class. That is, multiple interfaces are implemented in a class, and the process from one interface in the class to another is Qi (interface query ).

Here, I mainly mention two points: 1. interface query (or Interface Conversion) is for interfaces implemented by the same class. Qi cannot be performed between interfaces implemented by different classes. For example, Class A implements (inherits) The ia1, ia2, ia3, and ia4 interfaces. Class B implements (or inherits) the interfaces ib1, ib2, ib3, and ib4. Then, the four interfaces in Class A (A1 ~ A4) interfaces can be queried. The four interfaces of Class B (b1 ~ B4) can also be used for interface query, but the interfaces implemented by Class A and implemented by Class B cannot be used for interface query, that is: interface query is limited to multiple interfaces implemented by the same class.
Interface query (or Interface Conversion) is for interfaces implemented by the same class. Qi cannot be performed between interfaces implemented by different classes. For example, Class A implements (inherits) The ia1, ia2, ia3, and ia4 interfaces. Class B implements (or inherits) the interfaces ib1, ib2, ib3, and ib4. Then, the four interfaces in Class A (A1 ~ A4) interfaces can be queried. The four interfaces of Class B (b1 ~ B4) can also be used for interface query, but the interfaces implemented by Class A and implemented by Class B cannot be used for interface query, that is: interface query is limited to multiple interfaces implemented by the same class.
2. Why interface query? When we instantiate a class with the New Keyword and save the reference of this class instance to a variable of the interface type (Note: This class implements this interface), such: ia1 a1 = new A (); we know that Class A implements four interfaces. However, object a currently can use only the attributes and attributes defined in interface ia1, you cannot use the attributes and methods defined by the other three interfaces. However, if we want to use the methods and attributes defined by the other three interfaces (ia2, ia3, ia4), we need to use Qi at this time.
The following two examples are used to explain the use of Qi.
First, we define two interfaces and a class as follows:
// Two custom interfaces
Interface IMAP
{
Void clearlayers ();
}
Interface iactiveview
{
Void clear ();
}
// Defines a class that inherits the two interfaces defined above
Class mapclass: IMAP, iactiveview
{
Void IMAP. clearlayers ()
{
MessageBox. Show ("clearlayers method executed ");
}
Void iactiveview. Clear ()
{
MessageBox. Show ("the clear method is executed ");
}
}
Private void btntest_click (Object sender, eventargs E)
{
IMAP pmap = new mapclass (); // instantiate the class mapclass and save the object reference in the IMAP Type Variable
Pmap. clearlayers (); // call the method defined in the IMAP Interface
Pmap. Clear (); // if we call the methods in the iactiveview interface in this way, a compilation error will occur. The reason is that the clear () method is not defined in the interface IMAP. Currently, only the clearlayers () method can be used for class instances. What if I have to use the clear () method? At this time, Qi should exert its power.
Iactiveview pactiveview = pmap as iactiveview; // The Qi
()
Pactiveview. Clear ();
}
Let's talk about it today. I just started my study. If there is anything wrong with it, please criticize and correct it and make progress together. Some content refer to some online materials. Special instructions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.