如何公开一个接口的方法没有使它公众所有类使它、公众、接口、方法

2023-09-08 12:50:11 作者:黑咔王子 ?

我有一个问题,即我正与一个特定的接口,相当多的东西。但是,我有我想要只提供给特定的组类(基本上,一个内部方法)的特定方法。

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.