Ok, I'm used to structuring my projects like this
|--com.mycompany.interfaces
| |--IFoo1(public)
| |--IFoo2(public)
| |--IBar1(public)
| |--IBar2(public)
|
|--com.mycompany.foos.impl
| |--Foo1(default) implements IFoo1
| |--Foo2(default) implements IFoo2
|
|--com.mycompany.bars.impl
| |--Bar1(default) implements IBar1
| |--Bar2(default) implements IBar2
|
|--com.mycompany.services
| |-FooBarService (public)
I have one package to organize all interfaces and then the implementations are in their own related pacakges.
The public class FooBarService has to return instances of Foo1, Foo2, etc via their interfaces IFoo1, IFoo2, etc to callers outside this project. But class FooBarService cannot access the concrete classes Foo1, Foo2, etc as they are package scoped.
What is a good way to not expose the concrete classes to outside libraries but stil keep implementations in meaningful multiple packages? or is that even possible? In .net I can just specify concrete classes as internal
, where ever they are implemented and whatever their namespace is but I'm wondering if it's possible in java use such structure?