问题描述
我有一个问题,即我正与一个特定的接口,相当多的东西。但是,我有我想要只提供给特定的组类(基本上,一个内部
方法)的特定方法。
I have a issue where I'm working with a particular interface for quite a lot of things. However, I have a particular method that I want to be available only to a particular group of classes (basically, an internal
method).
interface IThing {
function thisMethodIsPublic():void;
function thisMethodShouldOnlyBeVisibleToCertainClasses():void;
}
现在的问题是,有没有办法在一个界面中添加访问修饰符(如公共,私有,内部) - 至少在ActionScript 3.0。
The problem is, there is no way to add access modifiers (i.e. public, private, internal) in an interface - at least not in ActionScript 3.0.
所以,我不知道什么是最好的做法吗?这似乎是不好的形式,使这个内部方法公开,但我需要它的界面的一部分,所以我可以保证,实现IT类有这样的内部方法。
So I'm wondering what would be the best practice here? It seems like bad form to make this internal method public, but I need it to be a part of the interface so I can guarantee that classes that implement it have this internal method.
感谢您的帮助!
推荐答案
答:定义两个接口,并保留了私人功能,在第二个接口。如果ActionScript支持继承的接口,然后定义私人界面,扩展了公开的界面。
Answer: Define two interfaces, and keep the 'private' functions in the second interface. If ActionScript supports inheritance for interfaces, then define the 'private' interface as extending the 'public' interface.
这篇关于如何公开一个接口的方法没有使它公众所有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!