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

前端 未结 5 667
无人共我
无人共我 2021-01-19 18:01

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

5条回答
  •  日久生厌
    2021-01-19 18:07

    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.

提交回复
热议问题