If I have the interface accessible from all modules, but implementation cannot be accessible, how can I instantiate this from other modules?
If I have 3 modules, one module is accessible to all which has my interface, and the other 2 modules have no access to each other. How can I instantiate this interface?
How to access an implementation without adding Maven dependency?
Add a factory class alongside the interface. This factory can either be instantiated easily or provide a static method such as public static StuffFactory getInstance() {
This factory is in charge of creating new instances of your interface. Example:
public Stuff newStuff() {
return new StuffImpl();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.