Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expose a method in an interface without making it public to all classes

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

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.

Thanks for your help!

like image 672
Mims H. Wright Avatar asked Dec 13 '22 01:12

Mims H. Wright


2 Answers

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.

like image 64
Craig Trader Avatar answered Jan 19 '23 23:01

Craig Trader


One possible idea I just thought of would be to define a second interface for the internal method:

interface IThing {
    function thisMethodIsPublic():void;
}

interface IInternalThing {
    function thisMethodShouldOnlyBeVisibleToCertainClasses():void;
}

That way the method would not be visible without type casting when working with IThing, but would be when you explicitly type cast as IInternalThing. This doesn't really solve the problem but it makes that method a little more hidden.

like image 30
Mims H. Wright Avatar answered Jan 20 '23 01:01

Mims H. Wright