Well, another way is to have two different interfaces. One for your public API and one for your internal API, your Class2 object will implement both. Everyone who deals with the API will talk to him through the open interface that you opened
public class Class2 implements PublicApi2 { public void somePrivateMethod() { ... } @Override public void somePublicMethod() { ... } }
(two interfaces were not implemented here, since there is really no need for a "closed" one, since the objects in your library / framework / everything can deal with specific classes, but this is up to you)
Clients will always refer to your object as a type of "PublicApi2" and will never deal with a specific implementation (Class2), while your internal clans will.
source share