简体   繁体   中英

How to resolve the dependency between two modules

I have two modules - module A and module B. In Module A, I have my Mailer.java whose method I have to call from a java class in module B, in such a way that they are not highly coupled nor there should be any cyclic dependency (if possible) between the 2 modules.

I thought of moving the Mailer.java code in module B, but that does not help because that Mailer.java has many more dependencies which I will have to move to module B.

Then I thought of writing an interface in module B with a method that will be implemented in module A. Eventually, I will then end up calling that implemented method. But then since it is an interface method, I will have to give default body to that method in module B. But I am not convinced with this solution. Is the solution alright?

Any other way of implementation will also help.

Two approches I can suggest.

1) seperate out the common module and make it a shared library between A & B.

2) Expose webservices, that can be consumed by other modules.

create has a relationship of Module A in Module B

if any class in Module A wants a class in B then instantiate it use it.

for eg, instantiate Mailer.java in Module B so that all the methods can be exposed to it to use in Module B.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM