I want to separate the api from the implementation, and making implementation module depends on api modules, however I encounter the problem that api actually depends on the implementation and don't know how to proceed.
Api/Builder.java
public interface Builder{
static Builder create(version) {
if (version < N)
return new subBuilder1()
else
return new subBuilder2()
}
}
Impl/subBuilder1.java
public static class subBuilder1 implements Builder{
public subBuilder1() {......}
......
}
Impl/subBuilder2.java
public static class subBuilder2 implements Builder{
public subBuilder2() {......}
......
}
Builder is an interface and I want to move it into api modules.
subBuilder1 and subBuilder2 are actual implementations, and they are currently in implementation modules.
Since currently implementation module depends on api module, I couldn't move the interface Builder into the api module as Builder actually depends on the subBuilder1 and subBuilder2.
How to solve this problem of API invokes implementation? Will dependency injection work for this case?