I need help with clarifying my (mis)understanding of the Single Responsibility principle (SRP).
In many projects that I have worked on, my colleagues argue that the SRP means that a class should implement very limited functionality, e.g. calculating some totals over a collection of objects. This leads to classes that have one public method (one responsibility), e.g. CalculateTotals(...)
. I'm not a DDD expert, but from what I have seen this leads to Anemic Domain Model, DTOs and endless micro services.
Taking this approach and adding DRY to the mix leads to reuse of those classes in different parts of the application.
I tend to think of SRP on a higher level, the requirements level. For example, totals need to be calculated for reporting vs. totals need to be calculated for tax related calculations. Applying DRY in this situation can lead to unexpected bugs. When the totals calculation logic needs to change due to changes in reporting requirements, if we have applied DRY and reused the class, we will break our tax calculations.
Given that a reason for a change should come only as a result of a change in the requirements (I don't think that re-factoring applies here) should the DRY principle be scoped only within a single use case?
If the above statement is correct, does it mean that we don't have to break the tax calculation into a separate class? Well, we could do it to simplify the code, but would we not do for SRP reasons?
Am I wrong in my thinking?