Reputation: 1876
Let's take a look at the following code:
package A;
public interface MySuperInterface{
enum MyENUM { ...}
}
public class MyImplementingClass implements MySuperInterface{
public void someFunction(MyENUM e);
}
package B;
import A.MyImplementingClass;
public class MyClientClass{
MyImplementingClass mic = new MyImplementingClass();
mic.someFunction( /* here's my question. I need MyClientClass to know only about MyImplementingClass and nothing about MySuperInterface */);
}
As you can see above, in order to use someFunction()
, MyClientClass
needs to know about a (ENUM) type called MyENUM
which is defined inside MySuperInterface
. My question is, is it possible to design MyClientClass
to know only about MyImplementingClass
and nothing about MySuperInterface
?
In other words, MyClientClass
doesn't need to import MySuperInterface
.
Update This code is for illustration only. The reason why I am asking this is to know about Maximum Encapsulation. In other words, I want to know if it's possible that a client can use a Class without knowing anything about its ancestors (superinterfaces, superclasses).
Upvotes: 1
Views: 59
Reputation: 8594
All static members of MySuperInterface
are also available on MyImplementingClass
, so your client code can just do this:
mic.someFunction(MyImplementingClass.MyENUM.FOO)
Upvotes: 3