views:

44

answers:

1

Hey guys,

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 insight.

+3  A: 

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

PatrickS
+1 this is definitely the way to go
Tyler Egeto
It'd have to be a public method to override it, wouldn't it? Or is that not the case when you use the override keyword?
mway
Either way - great advice, I think I'll do just that. Thanks for your help!
mway
no, only the private class could not be overridden, since it's not accessible to the subclass. i didn't use internal, as you would have to create the subclass in the same package.
PatrickS