我知道根据定义,AS3接口必须是公共的,并且其中的方法也必须公开实现.
我读了这个问题,我想如果你想让一些类选择是否实现某些方法,但是有一些必须在实现任一接口的所有类中实现的通用基本方法,答案是显而易见的.
考虑到这一点,即使有了"私有实现"的想法(实际上并非如此),最好的想法仍然只是在接口之外为所有类显式定义私有方法?问题不是强迫某些类实现不同的方法,而只是这些方法的一般可见性.我猜的答案是"是",但我想我会看到是否有人有任何见解.
尽管AS3不支持抽象类,但为什么不定义一个要用作抽象类的类,并让它实现该接口并定义该类中的非公共方法.
interface IThing { function thisMethodIsPublic():void; } public class ThingAbstract implements IThing { //throw an Error to avoid calling the class directly, //this class needs to be subclassed //and this method overridden protected function thisMethodShouldOnlyBeVisibleToCertainClasses():void { throw new IllegalOperationError ('this method should be overriden in a subclass'); } public function thisMethodIsPublic():void { } }
归档时间: |
|
查看次数: |
1607 次 |
最近记录: |