We have a main service class
in which we initializes many primitives
and non-primitive(objects)
variables, via calling other downstream services
or forming these variables on the fly as they are required later in the logic. Controller
class this main service
class.
At the end of main service
class, after calling all downstream services and initializing these variables. We call a loggingService
class, which needs all those variables that we initialized and make a loggingObject
and push this to downstream service for tracking purpose. The structure of this loggingObject
is very dynamic and keep changing at any time(fields will get added anytime anywhere in the structure).
Problem Desc: loggingMethod
(method in loggingService) arguments are keep growing as going forward more intermediate objects and variables will be added dynamically and we have to send them all to downstream service for tracking purpose. As we believe there should not be too many params to a functions (we are keeping in our codebase <= 4
).
We thought of initializing one global object
(An aggregate GOD object) for a request, that should be accessible everywhere in the codebase (OR we keep passing this object in every downstream service method), and we add all those intermediate objects/variables in this global object and send this global object in the loggingMethod
.
Using global object might be an anti-pattern here. Would this be the right approach to tackle this problem, OR there could be a better design pattern to solve this, keeping in mind that we want to keep it extensible for future field additions.
Application is written in spring-boot(Java-11).
Aucun commentaire:
Enregistrer un commentaire