简体   繁体   English

AS3 / Flex:接口扩展接口

[英]AS3/Flex : Interface extends interface

In AS3/Flex, is it possible for me that one interface extends another interface ? 在AS3 / Flex中,我可以将一个接口扩展到另一个接口吗?

I have created interface A. Now I want to create another Interface B which extends interface A. 我创建了接口A.现在我想创建另一个扩展接口A的接口B.

I google a lot but couldnt find any convincing answer. 我谷歌很多,但无法找到任何令人信服的答案。 Please help. 请帮忙。

Of course you can extend an interface : 当然你可以扩展一个界面

Multiple interfaces can be inherited by another interface through the extends clause or by a class through the implements clause. 多个接口可以通过extends子句通过另一个接口继承,也可以通过implements子句通过类继承。 Instances of a class that implements an interface be long to the type represented by the interface. 实现接口的类的实例长到接口所表示的类型。 Interface definitions must only contain function definitions, which may include get and set methods. 接口定义必须只包含函数定义,其中可能包含get和set方法。

Keep in mind: Sometimes it is faster to just try it out or simply look in the Flex SDK source code. 请记住:有时候尝试一下或者只是查看Flex SDK源代码会更快。 ;-) ;-)

${FLEX_HOME}\\frameworks\\projects\\framework\\src\\mx\\core\\IUIComponent.as : ${FLEX_HOME}\\frameworks\\projects\\framework\\src\\mx\\core\\IUIComponent.as

package mx.core
{ 
...
public interface IUIComponent extends IFlexDisplayObject
{
...

In my comment I said Interfaces aren't extended; 在我的评论中,我说接口没有扩展; they are implemented. 它们已经实施。 That should have been that interfaces are implemented by classes using the implement keyword. 应该是使用implement关键字通过类实现接口。 When you want a single interface to 'extend' multiple interfaces, just use the extends keyword and separate them by commas. 当您希望单个接口“扩展”多个接口时,只需使用extends关键字并用逗号分隔它们。

Take this interface, IMyFirstInterface: 拿这个界面,IMyFirstInterface:

public interface IMyFirstInterface {
 // method definitions here
}

And then take, this other interface, IMySecondInterface: 接下来,这个其他接口,IMySecondInterface:

public interface IMySecondInterface {
 // method definitions here
}

Both are "Stand alone" meaning they don't have any relation to another interface. 两者都是“独立”意味着它们与另一个界面没有任何关系。 But, a third interface can extend them both, like this: 但是,第三个接口可以扩展它们,如下所示:

public interface IMyThirdInterface extends IMyFirstInterface, IMySecondInterface{
 // method definitions here
}

Your class will implement the Interface, like this: 你的类将实现接口,如下所示:

public class myClass implements IMyThirdInterface{
 // other class stuff
}

myClass is required to include all the methods defined in iMyThirdInterface, IMyFirstInterface, and iMySecondInterface because it implements IMyThirdInterface which extends IMyFirstInterface and IMySecondInterface. myClass需要包含iMyThirdInterface,IMyFirstInterface和iMySecondInterface中定义的所有方法,因为它实现了IMyThirdInterface,它扩展了IMyFirstInterface和IMySecondInterface。

Off the top of my head; 脱离我的头顶; I have no idea how "collisions" are handled. 我不知道如何处理“碰撞”。 If IMyFirstInterface and IMySecondInterface implement the same method with different signatures I would expect a compiler error. 如果IMyFirstInterface和IMySecondInterface使用不同的签名实现相同的方法,我会期望编译器错误。

Interfaces can extend other interfaces. 接口可以扩展其他接口。 Classes can extend classes. 类可以扩展类。 See the correlation here? 看到这里的相关性? Its like lego. 它就像乐高。

Interfaces implement classes. 接口实现类。 Classes implement interfaces. 类实现接口。 It should make sense now. 它现在应该有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM