如何在不公开给所有类的情况下公开接口中的方法 [英] How to expose a method in an interface without making it public to all classes

查看:35
本文介绍了如何在不公开给所有类的情况下公开接口中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我正在使用一个特定的界面来处理很多事情.但是,我有一个特定的方法,我希望它只对特定的一组类可用(基本上,一个 internal 方法).

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.

所以我想知道这里的最佳做法是什么?公开这个内部方法似乎是一种不好的形式,但我需要它成为接口的一部分,这样我才能保证实现它的类具有这个内部方法.

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.

这篇关于如何在不公开给所有类的情况下公开接口中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆