I’m involved in developing an application that has a somewhat complex data structure. My first attempt was not successful, because the objects ended up having more than one responsability, while other responsibilities were divided between more than one model.
I need the opinion of you to help me get a good proposal for the structure of data.
Each user (or group of users) of the application belongs to an organization. Think of each organization as a completely independent environment, such as a CRM or ERP, i.e., the data of one company do not relate to the data from another company.
Each organization has several customers (which we will call Atom). Every month the user will upload the consolidated purchase of each customer (total and by product) . These data will be crunched and three different analyzes will be generated: Performance Analysis, Goal Analysis and Price Analysis. The point I’m more concerned about is related to the fact that we’re dealing with monthly data.
I would not want to rely on a date attribute to relate (i) the total purchase; (ii) the purchase by product; (iii) performance analysis; (iv) goal analysis and (v) price analysys all within the same month. I think the app would be more organized if I could relate all these models to a Month object.
For example, when displaying the page of a client, I would like to show all your analysis results. I could get it by date. But analysis does not have different days, they are consolidated by month, then it makes more sense to look for analyzes that belongs to a Month.
I’m picturing something like:
MonthData AtomTotalData belongs_to MonthData AtomProductData belongs_to MonthData MonthAnalysis PerformanceAnalysis belongs_to MonthAnalysis GoalAnalysis belongs_to MonthAnalysis PriceAnalysis belongs_to MonthAnalysis
where I separate raw data from analysis. The problem is that this way, I do not have a direct relationship between the raw data and their analysis. They belong to the same month, but they within the app, they belong to different objects.
I could also do:
Month AtomTotalData belongs_to Month AtomProductData belongs_to Month PerformanceAnalysis belongs_to Month GoalAnalysis belongs_to Month PriceAnalysis belongs_to Month
In this case, every object belongs to the same Month object, but feel like I’m hurting the Single Responsibility Principle because the Month object adds both raw data and analysis.
A third option would be similar to the first, but MonthData and MonthAnalysis objects belong to a Month object. I feel that in this case I would be adding too much objects.
So I have some questions:
Do you think that my concern about creating a Month or MonthData object so that I do not only depend on the data attribute makes sense?
Which of the following alternatives do you think makes is the best? I have some concern with performance.
Is there another option I’m not considering?