While developing an application (mobile app for Android), our team always strives to use best development practices such as interfaces, layering and separation of concerns.
When it comes to reporting analytics events from our app, the requirements sometimes force us to send events with data that is stored and managed by multiple different app “components”.
Some of this data is not directly available at the component/layer that does the reporting, nor at any central location in the application.
To me, this seems like it contradicts all the efforts of architecture and design that were made during the development of the application.
My question is:
What is the correct way to deal with this issue?
Is the problem in the requirements we received, or is it a common issue that a layered/modular application sometimes needs to make things “global” ? if so, what is the way to solve this issue while still reaping the benefits of development best practices?
One of the principles of layered structure is that every layer call only the layer below and receive callbacks. So if the reporting layer does not provide access to this data, it is fair to assume that the data is not accessible from any other layer above.
I don’t think adding globals is a good idea. It makes the architecture inconsistent and adds very little (if any) value. I would rather add the missing functionality to the reporting layer. In this case the reporting layer could call the component(s) managing the data and forward it to the original caller.
There might be deeper considerations if the data itself is distributed among different components. But anyway, having a single interface for all the data will make the structure clear and easier to maintain.
2