Question
I'm writing monolith application that consists from multiple modules. For the sake of example there are two modules: Module_B
depends on Module_A
.
To achieve low coupling and make it easier to split my monolith to separate services in future, I arranged communication between Module_B
and Module_A
through ModuleAClient
(see code below).
Should I share some of Module_A
's request/response objects or duplicate them inside Module_B
?
Share Module_A request/response
In example below I pass com.moduleA.ModuleARequestObject
to and return com.moduleA.ComplexGraphResponse
from buildGraph
method. That mean that com.moduleA.*
objects are spread across Module_B
's classes. Does it mean higher coupling? If I change ComplexGraphResponse
inside Module_A
, Module_B
will also change it behavior (may be broken).
Duplicate Module_A request/response
In other hand, duplicating some of complex Module_A
request/response objects is an extra work and I can't see how it save me from high coupling. If I change ComplexGraphResponse
inside Module_A
, Module_B
will fail to map ComplexGraphResponse
to ComplexGraphResponseBDuplicate
and will also fail.
Example
package com.moduleB.client;
// QUESTION: should I map moduleA request/response objects to moduleB request/response objects?
import com.moduleA.ComplexGraphResponse;
import com.moduleA.ModuleARequestObject;
//This class is located inside Module_B
@Service
public class ModuleAClient {
@Resource
private ServiceA serviceA;
public ComplexGraphResponse buildGraph(Set<ModuleARequestObject> objects) {
return serviceA.buildGraph(objects);
}
}
P.S.
I have found this question. Is it the same? Do you agree with response?
Aucun commentaire:
Enregistrer un commentaire