Implement interface 5

xiaoxiao2021-03-06  59

4, mapping interface

Categories must provide specific implementations for members of all interfaces listed in the base class table. The implementation of the interface mapping is called an interface mapping.

Mapping, math representation of the corresponding functional relationship. The meaning of the interface mapping is also the same. The interface is implemented by a class, so for each member defined in the interface, a member of the class should provide a specific implementation for it.

The following conditions must be met between members of the class and the project it mapped.

1. Both A and B are members of the members, the name, type, and type reference (including the number of parameters, and the type of each parameter) should be consistent.

2. If A and B are attributes, the names of A and B should be consistent, and the accessors of A and B are also similar. However, if a is not an explicit interface member executive, a allows you to add your own accessor.

3. If A and B are time, the names of A and B, the type should be consistent.

4. If A and B are index indicators, the types A and B are type, and the number of references (including the number of parameters, and the type of each parameter) should be consistent. And the A and B accessers are also similar. However, if a is not an explicit interface member executive, a allows you to add your own accessor.

So, for an interface member, how to determine which class member is implemented? What kind of member map is an interface member map? Here, we describe the process of interface mapping. Assume that class c implements an interface IINTERFACE, Member is a member in the interface IINTERFACE, who is positioned by who the interface member MEMBER, that is, the MEMBER mapping process is like this:

1. If there is a explicit interface member actuator in C, the actuator corresponds to the interface IINTERFACE and its member MEMBER, and it implements the Member member.

2, if the condition (1) is not satisfied, and there is a non-static public member in C, which corresponds to the interface member MEMBER, which is made by Member members.

3. If the above conditions are still unsatisfactory, look for a c class d in the base class list defined by class C, with D instead of C.

4. Repeat steps 1-- 3, traverse all direct base classes and non-direct base classes of C until a member of the class satisfying the condition.

5. If you still haven't found it, the report is wrong.

Below is an example in which a base class method is invoked to implement interface members. Class Class2 implements the interface interface interface1, class class class class class class class class Class1 member also participates in the interface mapping, that is, when the class class2 is implemented when the interface interface1 is implemented, the member method F provided by the class class1 is implemented by the interface Interface1. Method F:

Interface interface1 {void f (); class class1 {public void f () {}} class class2: class1, interface1 {new public void g ()}}

Note: Members of the interface include their own definition, and include members of all parent interfaces defined by the interface. When the interface map is mapped, it is necessary to map all members of the explicitly defined defined in the interface, but also map all interface members implicitly inherited from the parent interface.

转载请注明原文地址:https://www.9cbs.com/read-83484.html

New Post(0)