开发者

AS3: Interfaces & Nonpublic Methods

I know that by definition AS3 interfaces must be public, and the methods within them must be implemented as public as well.

I read this question and I suppose the answer is obvious if you want to have some classes choose whether or not to implement some methods, but have common base methods that must be implemented across all classes that implement either interface.

With that in mind, even with that 'private implementation' idea (which really isn't), is the best idea still to just explicitly define a private method for all classes, outside of the interface? The issue isn't forcing some classes to implement different methods, it's just the general visibility of those methods. I'm guessing the answer is "yes", but I figured I'd see if anyone had any insig开发者_开发百科ht.


Although AS3 doesn't support abstract classes , why not define a class to be used as an abstract class and have it implement that interface and define the non public methods inside that class.

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
  {
  }
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜