mercredi 20 septembre 2023

Message passing vs memory manipulation

My app consists of different decoupled modules and usually the output of one module is the input of the next module. However for a specific use case I want to collect data across all modules and print it out in the end. I see two options:

  1. Message passing: Passing a container object through the different modules which fill it with data. This is how I would usually do it since the hardcoded dependencies make the code very clear and understandable. However, refactoring really becomes annoying, since I often need to change the arguments and return-values of the call hierarchy. Also, I'm not sure if just passing a "container/collector object" and filling it without explicitly returning it is a good design approach.
  2. Memory manipulation: Injecting the container object at all places where I need to collect data data. Inject the object also at the place where I need to retrieve the data. Allows for quick refactoring since I just need to inject the collector/container object at the specific places. However, it feels like the code becomes hard to understand, since i don't have a call hierarchy to understand where the information is coming from.

Are there reasons to prefer one option over the other in my scenario or in general?

Aucun commentaire:

Enregistrer un commentaire